Skip to content
Baltasar García Perez-Schofield edited this page Oct 20, 2017 · 4 revisions

Variables

Pueden crearse variables de cualquier Tipos dado. En primer lugar se indica el nombre del tipo, y a continuación el nombre de la futura variable. Si se desea indicar un valor inicial, entonces a continuación se incluye el signo de asignación ('=') y el valor deseado. Nótese que, en caso de no indicar un valor inicial, entonces la variable tendrá como valor el contenido de la posición de memoria antes de ser creada.

You can create variables of any of the available types. First time you write the type of the variable to create, then its name. You can provide an initial value by following that with an equal sign ('=') and the desired value. You must take into account that, if an initial value is not provided, then the variable will have the same contents that was in the variable position before creating it.

El valor inicial puede ser escrito como el nombre de otra variable ya existente (la nueva variable tomará su valor), o como un literal. Para un entero es simplemente un valor como 5 (o 0x5 en hexadecimal). Para un carácter, el literal es una letra, número o símbolo encerrado entre comillas simples. Para un número real, se indica como 5.6, separando la parte entera de la fraccionaria por un punto (las preferencias regionales son ignoradas). Un caso especial son los vectores de caracteres, que normalmente se utilizan para almacenar texto (indicando el final con el carácter de valor cero). En el caso de querer escribir un texto, se debe encerrar entre comillas dobles, como en "hola".

The initial value can be written as the name of an already existing variable (the new variable will take its value), or as a literal. For an integer it is just a value like 5 (or 0x5 for hexadecimal). For a character, the literal is a letter, number or symbol enclosed in simple quotes. For a real number, the integer part is separated from the decimal part by a dot '.', as in 5.6 (regional settings are ignored). An special case are vector of chars, which are used to store text (the end is signaled by a character of value zero). If you need to write a text, you must enclosed it in double quotes, as in "hello".

Caracteres

char ch = 'a'
> 97: 'a'
printf(ch)
> 'a'

Enteros

int x = 5
> 5
printf(x)
> 5

Reales

double pi = 3.14
> 3.14
printf(pi)
> 3.14

Cadenas de caracteres

printf("Hello!")
> 0xffffffff: "Hello!"
char * s = malloc(10)
> 0x8
strcpy(s, "hello!")
> 0x8
s[0] = 'H'
> 'H'
printf(s)
> 0x8: "Hello!"
free(s)
> 0

Clone this wiki locally