------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------
Knowledge Point ①: output, input function formatting placeholders and formatting modifiers use
%c one character
%d decimal integer%ld: Long integer%lld:longlongint%hd:shortint
%i Decimal Integer
%o Eight-binary integers
%x,%x hexadecimal integer
%s A string that ends with a space, tab, or newline character.
%f,%f,%e,%e,%g,%g is used to enter real numbers, which can be entered in decimal or exponential form.
%p A pointer
%u reads an unsigned decimal integer%zd: unsigned long integer unsignedlong
%n the equivalent number of characters that have been read into the value
Percent Read% sign
The printf () function format modifier describes:
Minimum wide Field m (integer):
Specifies the number of columns that the output is accounted for; if M is a positive integer, when the Output data width field is less than M, in the domain to the right, the left redundant bits fill the space, when the output data width is greater than M, the actual width of all output; if M has a leader 0, the left redundant bit is 0;
Display precision. N (an integer greater than or equal to 0):
The precision modifier, after the minimum width field, is made up of a dot and subsequent integers, for floating-point numbers that specify the number of floating-point decimal digits for the output, and for strings that specify the number of substring characters to intercept from the left of the string.
*:
The minimum wide field m and precision. N is substituted to indicate that their value is not constant, and the output items of the printf () function are specified sequentially
#: Decorated with the format character F, E, G, used to ensure that the output of the data has a decimal, even if there is no decimal place, when the format character x is also used to ensure that the output hexadecimal number preceded by a leader 0x.
scanf () function format modifier:
Ignore input modifier *: Indicates that the corresponding input is not assigned to the corresponding variable after reading it.
Knowledge Point ②: often use code block {} to free up memory that is used by unnecessary variables.
Knowledge Point ③: (for interview) a wonderful way to exchange two integers.
Wonderful one:
[CPP]View Plaincopy
- A = b-a;
- b = b-a;
- A = B + A;
Wonderful two:
[CPP]View Plaincopy
- A = A^b;
- b = a^b;
- A = A^b;
Knowledge Point ④:scanf ("%d%d"); If there are spaces in the format string, you can use a Space, tab, carriage return
Knowledge Point ⑤: The result of the remainder operation% is the same as the result of the symbol except the two positive number after the remainder is added.
Knowledge Point ⑥:sizeof operator
sizeof is an operator that is not taken for granted as a function
sizeof can be used without adding ()
sizeof can add variables, constants, data types
With data type is required plus ()
Problems caused by directly defining variables behind knowledge points ⑦:if
[CPP]View Plaincopy
- if (> 6)
- int a = 5;//Error * * * * scope
- If you define a new variable after the IF, you must use curly braces
The following is also the same error
[CPP]View Plaincopy
- char c = ' + ';
- int a = 10;
- int B = 20;
- Switch (c)
- {
- Case ' + ':
- int sum= A + b;//error ****** scope
- printf ("and is%d\n", sum);
- Break
- Case '-':
- Intminus = a-b;//Error
- printf ("Difference is%d\n", minus);//Error
- Break
- }
Modify if you want to define a new variable after the case must be wrapped with {}
[CPP]View Plaincopy
- Switch (c)
- {
- Case ' + ':
- {
- int sum = a + b;
- printf ("and is%d\n", sum);
- Break
- }
- Case '-':
- {
- int minus = A-B;
- printf ("Difference is%d\n", minus);
- Break
- }
- }
Similarly, the For loop does not have {} and cannot define a variable after
[CPP]View Plaincopy
- for (int i = 0; i<; i++, a++)//This has an error scope
- {
- INTA = 10;
- }
Knowledge Point ⑧:c language can initialize the count variable in for//performance good, how I remember learning not to C + + can
[CPP]View Plaincopy
- for (int i=0; ...; ...)
Contrast
[CPP]View Plaincopy
int i = 0;//This case makes I stay in memory for too long
- while (I. ...)
⑨:for initial parameter scope problem of knowledge point
[CPP]View Plaincopy
- for (int i = 0; i<; i++)//scope This is the right loop body to perform 10 times
- {
- Inti = 10;
- }
Equivalent
[CPP]View Plaincopy
- for (int i = 0; i <; i++)
- {
- INTA = 10;
- }
[CPP]View Plaincopy
- for (int i = 0; i<; i++, a++)//This has an error scope
- {
- INTA = 10;
- }
There is an error scope below
[CPP]View Plaincopy
- for (int i = 0; i<; i++, a++)//This has an error scope
- {
- int a = 10;
- }
Knowledge Point ⑩: The trap of a comma-expression
For example:
[CPP]View Plaincopy
- for (int i=0,j=0; ...; ...) cannot be written for (int i=0,int j=0; ...) Use of a comma-expression
Knowledge point?: C language does not allow two function names there is no overloaded concept
Functions cannot be defined repeatedly but can be declared repeatedly
Knowledge point?: #include编译预处理命令与多文件团队开发
#include编译预处理命令可以认为是: Copy the contents of the following file into the current file
Multi-File Team development: The modules are compiled into. O are not linked successfully, together the link is delivered into the final program.
Link: merges all associated. o Target files and C-language libraries in the project to generate executables
1. function definition put. c file, function declaration put. h file
2. If you want to use a function defined in a. c file, you only need to include the. h file that corresponds to the. c file.
The role of 3..h files: copied by others. You do not need to pipe. h files when compiling links.
Knowledge point?: Array initialization: I've never seen one of these.
[CPP]View Plaincopy
- int ages[5] = {[3] = 19, [4] = 20};
This is possible.
[CPP]View Plaincopy
- int ages[] = {19,20};
The following is not true:
[CPP]View Plaincopy
- INTAGES[5];
- ages = {19, 20, 21, 22, 23};//array name is address
Here's what you can do.
[CPP]View Plaincopy
- int count = 5;
- int ages[count];//
- Ages[0] = 10;
- AGES[1] = 11;
- AGES[2] = 12;//But the value of ages[3]ages[4] is random
The following is not true:
[CPP]View Plaincopy
- int count = 5;
- int ages[count]= {10,11,12};//error
Conclusion: If the array is initialized when it is defined, the array element must be a constant, or do not write
Knowledge points?: Calculating the length of an array
[CPP]View Plaincopy
- sizeof (array name)/sizeof (array name [0])
- sizeof (array name)/sizeof (array type)
Knowledge points?: The length of an array cannot be evaluated inside a function when the array is a function parameter
Because the parameters are passed
Arrays are treated as pointers, and the length of a pointer variable is always 8 bytes in a C language in a 64-bit compiler environment
So in passing the parameter to pass the array length
Knowledge Point 16: String initialization
The first four of the following are strings
[CPP]View Plaincopy
- Char name[8] = "it";
- Char name2[8] ={' i ', ' t ', ' n '};
- Char name3[8] ={' i ', ' t ', 0};
- Char name4[8] ={' i ', ' t '};
That's not possible.
[CPP]View Plaincopy
- Char name4[] = {' I ', ' t '};//is not a string
Understanding the storage of strings in memory
[CPP]View Plaincopy
- Char name[] = "it";
- Char name2[] ={' o ', ' K '};
- printf ("%s\n", &name2.[ 1]);//kit
Knowledge Point 17:strlen function
1. Number of characters calculated: "Ha haha" length is 7
2. The calculated characters do not include ' + '
3. Start from the address of the incoming value until the first ' x '
Knowledge Point 18: When defining a pointer variable, you should initialize it at the same time
[CPP]View Plaincopy
- Int*p = &a;
Or
[CPP]View Plaincopy
- Int*p;
- p = &a;
Int*p; p = &a;
Try not to define after emptying such as: int *p;
Knowledge Point 19: Pointers are often used for functions where multivalued returns are used in C + + is reference
Knowledge Point 20: The difference between an array and a character pointer definition string
Define strings in two ways
1 Using arrays
Char name[] = "it";
Name[0] = ' T ';//This is OK, string variable
Features: Character of string can be modified
Usage Scenario: The contents of a string change frequently
2. Using pointers
Char *name2 = "it";
Name[0] = ' T ';//This is not possible, string constants
Features: The contents of the string can not be modified
Usage Scenario: The contents of the string do not need to be modified, and this string is often used
Knowledge Point 21: The same piece of memory when holding the same value in the constant area
[CPP]View Plaincopy
- #include <stdio.h>
- Intmain ()
- {
- Char *str1 = "ABCD";
- Char *str2 = "ABCD";
- printf ("Str1 's address is%p\n", str1);
- printf ("Str2 's address is%p\n", str2);
- return 0;
- }
The result of the execution is:
[CPP]View Plaincopy
- STR1 's address is 0x10373bf66.
- STR2 's address is 0x10373bf66.
Knowledge Point 22: Constant area, heap, stack
The programmable internal presence is basically divided into the following parts: Static storage, heap, and stack areas. They have different functions and different ways of using them.
Static storage: Within the time the program is compiled, it is already allocated, and the entire running period of the program exists in this block. It mainly stores static data, global data, and constants.
Stack area: When executing a function, the storage units of local variables within the function can be created on the stack, which are automatically freed when the function is executed at the end. The stack memory allocation operation is built into the processor's instruction set and is highly efficient, but allocates limited memory capacity.
Heap area: Also known as dynamic memory allocation. The program uses malloc or new to request any size of memory at run time, and the programmer is responsible for freeing the memory with free or delete when appropriate. The lifetime of dynamic memory can be determined by us, and if we do not release the memory, the program will release the dynamic memory at the end. However, good programming habits are: If a dynamic memory is no longer used, it needs to be released, otherwise, we think there is a memory leak phenomenon.
Knowledge Point 23: pointers to functions
[CPP]View Plaincopy
- void Test (int a)
- {
- printf ("%d\n", a);
- }
- void (*p) (int) = test;//fixed notation
- void (*p) ();p = test; ibid.
- (*p) (3);//function call, can also direct P ()
Dark Horse programmer--c Language Foundation---the easy omission in C language learning (Part I)