1. Constant is the amount of the program can not be changed during operation; A variable represents a storage area where the stored content is the value of the variable, and the value of the variable can be changed during program operation
(a variable is like a cup, used for storing water, and the value of the water in the cup is variable)
2. Basic data type: int: integer type, 4 bytes in memory, each byte in computer is represented by 8 binary system number; Short: Shorter integer type, 2 bytes in memory
Long: Length type, 4 or 8 bytes in memory, OS-related, 4 bytes in 32-bit operating system, 64 bytes in 8-bit operating system
FLOAT: single-precision floating-point type, which accounts for 4 bytes in memory; Double: dual-precision floating-point type, which accounts for 8 bytes in memory; Char: Character type, which accounts for 1 bytes in memory
3. Variable definition: Data type variable name = initial value
4. Naming conventions for variables:
A. There can only be numbers, letters, underscores, but not numbers start
B. Cannot be duplicate with system keyword
C. Variable names should be self explanatory (see the name of the understanding)
d. Variable name cannot be duplicate
E. When defining a variable, you can assign an initial value or do not assign an initial value, but in order to develop a good habit, it is recommended to assign an initial value when defining a variable (note: When defining a struct, it must not
Assigning initial values to struct members)
such as: A. int sum;//is used to find elements and
sum = 10;
b. int sum;//is used to find elements and
sum + = 10; no, because sum + + 10 is equivalent to sum = SUM + 10, at which point the second sum has no value, so you don't get the result you want.
Therefore, I feel that the habit of getting the initial value is better, I have not assigned the initial value of their own, are to need to assign values. But then we found that when we defined the variables,
Value is very good, so I want to develop habits, now I also in the stage of raising habits.
F. When defining variables, you should name them in a camel-like manner, such as int maxLength = 0; (if the variable name is composed of two or more than two words, the first word
The first letter of each word in the back of the female lowercase. Again as: int practiceforc = 0;
Of course, everyone's habits are different, can be written according to their own habits, but must conform to the first 4 norms.
5. Arithmetic operator + (summation),-(poor), * (for product),/(quotient; two integers quotient is an integer , if the two number is divided to obtain the fractional part , the two parties needing to participate in the calculation have at least one
is a decimal ),% (for remainder, both sides of the operation must be integers), + + (self-added, the value of itself plus 1),--(self-reduction, the value of its own minus 1)
It should be noted that: int i = 0;
printf ("%d\n", I); The printed result is 0.
printf ("%d\n", i++); First print out the value of I is 0, then the value of i + 1; The self-reduction principle is the same, first output the value of I, and then the value of I-1.
printf ("%d\n", ++i); First the value of I + 1, and then print out the value of I is 2, the principle of self-reduction is the same, first the value of I-1, and then output the value of I.
In addition, int i = 0, j = 0, sum = 0;
sum = i+++ (--J);//(The greedy nature of the system automatically identifies the first two plus signs together). Equivalent to j = j-1; sum = i + j; i = i + 1; The result of the execution is i = 1, j =-1, sum =-1;
6. Composite operator + =,-=, *=,/=,%=
int i = 0, j = 0; i + = j;//equivalent to i = i + j; The same rules apply to the remaining composite operators
7. The decimals stored in the computer are inaccurate decimals, avoid two equal decimals for comparison
8. Format the input/output function:
A. Output function: printf ("%d\n", variable name); Where%d indicates that the type of the variable to be output is an integer, \ n means a newline, according to the preceding or after%d, to determine whether to wrap first, or to print the value of the variable first
B. Input function: scanf ("%d", & variable name); Enter a number from the console and place it in the storage unit represented by the variable, note:%d cannot be added \ n, otherwise it will be offset from the keyboard's enter key
, that is, add \ n, after hitting the keyboard, the enter will not work.
9. If you want to output%, just write the percent in the output function, such as: printf ("%%%%"); The result of the output is
Output "or" When: printf ("\" ");//output" printf ("\");//Output '
C language Basic data types and naming conventions