1, the variable name consists of letters, numbers, underscores, cannot start with a number, and underscores are treated as letters. System variables typically begin with an underscore. Variable names cannot be keywords, keywords are: If, else, switch, float, int, etc.
2, four basic data types: char, int, float, double
int can be decorated with qulifer short, long. Short int means at least 16bit. int represents 32bit or 16bit. A long int represents at least 32bit. A short int cannot have a larger number of digits than an int, and the int cannot be larger than the number of long int digits.
You can also use Qulifer unsinged and singed to modify Char
The unsigned char range is [0,255],signed char range = [-128,127].
3, constant indicates
Numeric constants can be suffixed. The suffix is: l means long,l also means long, u or lowercase u represents unsigned.
Character constants, character constants have a numberic value. Its corresponding numberic value is determined by the character set of the machine. For example, the ASCII character set in the character ' 0 ' represents the value is 48.
In addition, a only byte-sized bit pattern can be represented by octal or hexadecimal, some special characters, such as the tab character, which are not directly represented (unlike a B c D e ....) ), which has a value of 11 in ASCII code. Therefore, it can be expressed as:
#define VTAB ' 013 ' This is the representation of the octal system
#define VTAB ' 0xb ' This is the hexadecimal representation
You can also use the representation of an escape character, such as the tab character's escape character representation: char C = ' \ t ';
There is also a character constant ' numberic ' which is worth mentioning, and its ASCII value is 0. It is a null character.
String constants: In fact, the bottom of a string constant is a character array. The character array marks the end of the string with null character '. For example, the string "abc" it is in the underlying storage format is ' a ' B ' ' C '
Understanding string constants and character constants makes it easy to distinguish between ' X ' and ' X '. The former is an integer of type int, which is an array of type char. Ha ha....
4, Declaration and initialization of variables
How to declare a variable:
Mode 1, int a,b,c;
Mode 2, int A; int b; int C;
Mode 3,int a = 1; int b = 2; int c = 3;
Initialization of variables:
Variables are automatic variable, static variable, external variable
For a automatic variable, it is initialized before it is used, or it is a garbage value, or undefined.
External variable and static variable default initialization value is 0
The qualifier const can be used to modify a variable, which indicates that the value of the variable will no longer change.
such as const char msg[] = "Warning:"; The element that represents the array no longer changes.
Const can also modify array parameters, such as int strlen (const char[]); Indicates that the Strlen function does not change char[].
5, type conversion--char when converting to int
Since Char has only one byte, when the highest bit of a char is 1 o'clock, when converting char to int, will int be a negative number?
This situation is dependent on the machine. Since int has two bytes, some machines will fill 0 of that byte in the high position, thus getting a positive number. Some machines are high-fill 1, then converted to negative numbers.
"The C programming Language--2" Types, Operators, and Expressions