Friday, August 11, 2017

C programming; Lesson 2: Variables

Types of data in the program:
                                constants (0, 5, 3,145)
                                variables (a, iNumber, p)

For naming (variables and functions), identifiers are used:
                                English alphabet letters (A - Z, a - z), numbers (0 - 9) and underscore ('_')
                                First sign must be a letter or underscore
                                The identifier may not be the same as one of the keywords

(Language C differs in lowercase, so that the identifiers a and A are different names). Before using any variable, it is necessary to declare it in order for the compiler to know how many memory locations to reserve for that variable. The Declaration consists of the type of variable and identifier.
for example:  int a, b, c;

No more variables with the same name can be declared in the same part of the program (in the same block). After the variable declaration, the translator will reserve a certain area in memory for that variable under that name. At that point, anything can be found in the memory at that point, so it is necessary to set its value before initial use of the variable (initialize).
for example:   int a;
                       a = 5;

or:   int a = 5;

The join operator changes the value of a variable, and the variable type remains unchanged. If the operands are to the left and right of the join operator of different types, the value is lowered to the operand type according to the defined conversion rules. On the left side of the join operator, there are only changeable objects (variables). Multiple assignment operators are allowed in the same command.




1 comment: