Variable definition and assignment (on)

First, the definition of variables
1. Variable:
In fact, it is to find a free place in memory, open up a space in accordance with the type of data to be stored, for storing data, and the memory address space to take a name that is a variable name.
2. syntax requirements: data type variable name;
① semicolon at the end, do not lose. Definition of a variable is a statement, C language, the statement is a semicolon at the end of.
② "data type" indicates what type of data you want to store what type of variables defined. Want to store integer is defined as int type; you want to store the decimal is defined as a float or double type; you want to store the character is defined as char type .......
③ "variable name" is what you want to play what the variable name, usually with the letters.
Second, the variable assignment
1. What is the assignment:
Variable is a memory cell storing data, the system memory when a well defined value into a variable, the value is usually already present in the memory space garbage value (assigned a value of the system meaningless). A number into a variable, this process is called "assignment." "Fu" or "give" meaning, so "to the variable assignment" means that a value is passed to a variable.
2. how assignment:
① assignment operator =
② assignment format is: variable name = value to be assigned; it means that the variable will assign numbers to the right = left. For example: i = 3; which represents a 3 to variables i, i at this time is equivalent to a 3.
③ Note: This is with mathematics = "equal sign" is not the same. C language = for assignment, variables to be assigned to the variable value of the right to the left, rather than left to the right of equal value.
C language is represented by double equal sign == equal, the transport operator is a comparison operator, and Mathematics "equal" mean the same thing.
3. one:
① variable definition and assignment can be written in two steps, one step synthesis can be written, in fact, the actual programming in the most used are combined wording.
Form as follows: Data type variable name = value to be assigned to;
For example: int i = 3;
It means defines a variable i, and 3 to assign this variable. It
int i;
i =3;
It is equivalent.
② the definition of variables may be defined once and a plurality of variables, such as:
int i, j;
This means defines a variable i and j.
③ Note: also define a plurality of variables, among variables are separated by commas.
④ The same can also assign values ​​to them at the same time define multiple variables:
int i = 3, j = 4;
Middle, or separated by commas, do not forget to enter the last semicolon.
 

Guess you like

Origin www.cnblogs.com/10543-yyy/p/12635642.html