First, the data type
variables
1. Naming rules
Letters (underlined "_" are considered letters), sequences of numbers, letters in front
The name of the library routine is usually preceded by an underscore, so the variable name does not begin with an underscore
Distinguish letter Case
Keyword does not make variable name
Variable name to be able to literally express the purpose of the variable
Local variables typically use shorter variable names, and external variables use longer names
2. Data type and length
1) The C language only provides the following basic data types
Char character type, occupies one byte
int shaping, usually reflecting the most natural length of integers in the machine used
Float single-precision floating-point type
Double dual precision floating point type
In addition, you can precede these basic data types with some qualifiers. such as Short,long and type qualifier signed,unsigned.
Use the sizeof () function to represent the number of bytes in the data type
2) How each data type is stored (to be continued)
3) data type conversion (to be continued)
3. Declaration of variables
All variables must be declared before they are used.
Initialize: The variable can be initialized at the same time as declared, and the initialization expression must be a constant expression.
Constants
1. Shaping Constants (L (L), U (U), 0, 0x (0X))
2. Floating-point constants (f (f), L (L))
3. Character constants, a character constant is an integer, and some characters can be represented as characters and string constants by escaping a sequence of characters, such as \ n.
4. String constants, from a technical point of view, a string constant is a character array. The internal representation of a string uses a null character ' s ' as the end of the string. So the number of physical storage units that store strings is one more than the number of characters in double quotes.
The standard library function strlen (s) can return the length of the string parameter s, but the length does not include the end of ' + ', thus we can design a strlen function as follows
/*strlen function: Returns the length of S */int strlen (char s[]) {int i = 0; while (s[i]! = ' ++i '); return i;}
5. Enumeration constants
Second, operator
Arithmetic Operators
+ 、-、 *,/,% (remainder operation can only be used for integer type)
Relational Operators
> >= < <=
== !=
logical Operators
! && | | (the expression whose connection is evaluated from left to right, and stops the calculation immediately after knowing that the result value is False or True )
bitwise operators (only for integer operands) (to be continued ...) )
~ | & ^ << >>
Type Conversions (when several operand types of an operator are different, they need to be converted to a common type by some rules)
Auto-Convert: Converts "narrower" operands to "relatively wide" operands without loss of information
Cond......
operator Precedence and evaluation order
Control Flow (Control flow statements in program language are used to control the order of each calculation operation.) )
Branching Control Flow
1.if-else
2.swich-case
loop Control Flow
1.while
2.do-while
3.for
Jump
1.break
2.continue
3.goto
This article is from the "Yunfei Dance" blog, please make sure to keep this source http://wuyunncu.blog.51cto.com/5978596/1684851
C-Language learning notes-basic grammar