002-C language overview, 002-c Overview
C Language
Keywords:
32 keywords, all in lower case
Auto double int struct break else long switch
Case enum register typedef char extern return union
Const float short unsigned continue for signed void
Default goto sizeof volatile do if while static
Identifier
Custom symbols and names. It cannot be the same as the keyword.
Naming rules
1. Composition: 26 English letters, 10 digits 0 ~ 9, underline _
2. Case Sensitive
3. It cannot start with a number.
4. Keywords cannot be used as identifiers
Note
Explain the meaning of a line of code. The location is not fixed. But it is best to put the line on the code or behind the line. The annotation Code does not participate in compilation.
Single line comment: // single line comment
Multi-line comment:/* multi-line comment
Multi-line comment */
Data
Static and Dynamic Data
Static Data: hard disk, not related to computer power-on or shutdown
Dynamic Data: in memory, all data is lost after the computer is shut down
Data Type
1> constant
Integer constant (), float constant (double, float) character constant ('A', 'B'), String constant ("asdfadsfas ")
2> Variables
Variables can be used to represent the amount of constantly changing data during use.
Definition method: variable name of the variable type;
Int score; // Definition
Score = 100; // value assignment
Scanf Functions, Get user input
int age;
scanf("%d", &age);
The scanf function waits for the user's keyboard input and does not run the code later. The first parameter of scanf is "% d", which indicates that the user must enter an integer in decimal format. Note,The first parameter of scanf is not the age variable, but the address of the age variable & age,& Is an address operator in C. It can be used to obtain the address of a variable..
Printf function, Output data
printf("%d", age);
The function prototype is extern void printf (const char * format,...); multiple parameters are acceptable.
For example
1 int I, j; 2 scanf ("% d, % d", & I, & j); 3 printf ("I = % d; j = % d ", i, j); // multiple parameters. Multiple values are output.
Variable Scope
From the defined sentence to the end of the code block.
A code block is all the code inside a braces. The variable scope defined within a code block is the code block.
1 int main ()
2 {
3 int scores = 100;
4 {
5 int score = 200;
6 printf ("% d", score); // The output is 200.
7}
8 printf ("% d", score); // The output is 100.
9}
Local variables (variables defined inside the function) and global variables (variables defined outside the function)
Local variables in the function overwrite the global variables.
Memory Address
The memory address is continuous, in bytes.
Char 1; int 4; float 4; double 8
Variable Memory Address Allocation, memory addressing from large to small, so the first defined address value is relatively large.
Int a = 10;
Printf ("the address of a is: % p", & a); // % p is used to output the address, & is used to get the variable address
To be continued ......