Foreword: The purpose of this article is to record the easy-to-ignore details in C language. I plan to take a little time every day to read and tidy, persist, today is the first, perhaps next month's today is the second one, next year's Today is the third? ...... I firmly believe that a good memory is inferior to bad writing. The fourth article, fight~ ...
First link: Easy to ignore in C language details (first article)
Second Link: Easy to ignore in C language Details (second article)
Third link: easy to ignore in C language Details (third article)
1,the void* type of pointer can not participate in arithmetic operations, only for assignment, comparison and sizeof operation reason?
The arithmetic operation of the pointer also contains the byte number information of the object that the pointer refers to.
2, "&" can not be used alone for a non-variable thing. You cannot use "&" for literal constants to take their addresses, because literal constants are stored in the symbol table without an address concept. The array name is a pointer constant, and the value of the array name cannot be modified. For example, the following statement 1 is equivalent to statement 2:
int a[10];                  Statement 1int *const A;               Statement 2int B[3][4];                Statement 1int (*const b) [4];          Statement 2int C[3][4][5];             Statement 1int (*const c) [4][5];       Statement 2
3,return 0 and exit (0) a few differences
(1)exit end the entire running program, as long as the call exit to the end, it returns parameters to the OS, the control to the operating system; return exits the current function, returns the function value, gives control to the calling function;
(2)exit is the system call level, which represents the end of a process; return is a language level that represents the return of the call stack.
(3)The Exit function is also implicitly called at the end of the main function, which deletes the memory space used by the process and returns the error message to the parent process.
(4)The main function returns an integer value that is equivalent to calling exit for the value.
4. The static modifier is a useful tool to reduce naming conflicts. For example: static int A; The scope of a is limited to one source file, and a is not visible for other source files. Variable A with the same name can be defined in multiple source files, as long as all variable A is defined as static, or only one of the variables is not static. The static modifier also applies to functions.
5. The C language allows programmers to control the amount of output data produced before writing, and this control is achieved through library function setbuf. For example: Setbuf (stdout, BUF); The statement notifies the input/output library that all output written to stdout uses BUF as the output buffer until the BUF buffer is filled or the programmer directly calls the contents of the FFLUSH,BUF buffer to actually write to stdout. The size of the buffer is defined by the Bufsiz in the system header file <stdio.h>. An example of "C pitfalls and pitfalls" is:
#include <stdio.h>int main (void) {char C;char buf[bufsiz];setbuf (stdout, buf); while ((c = GetChar ())! = EOF) Putchar (c); return 0;}
The above procedure is wrong. The last time the BUF buffer is emptied is part of the cleanup that must be done by the C run-time library before the program returns to control to the operating system after the main function finishes. Prior to this, the BUF character array has been freed. There are 3 ways to modify it:
(1) defines the buffer array as static array, Buf[bufsiz];
(2) the buffer array is taken out of the main function;
(3) dynamic allocation of buffers, the program does not actively release the allocated buffer. Setbuf (stdout, malloc (Bufsiz));
Note:
(1) since the buffer is dynamically allocated, the buffer is not freed at the end of the main function, so that no buffer has been released when the C run-time library cleans up.
(2) if the malloc call fails, a null pointer is returned, at which point the standard output does not need to be buffered.
(3) for a file opened by a write operation, calling Fflush causes the contents of the output buffer to be actually written to the file.
 
6. Why is it necessary to pass a multidimensional array to a function without having to describe the length of the first dimension and the other dimension lengths?
(1) array elements are stored in memory according to the "row first" rule, and the number of columns is required to determine how many elements are in a row;
(2) The compiler does not need the length of the first dimension of the array when calculating the address of the element, but requires the length information of all other dimensions;
(3) C + + does not check the array for cross-border access, and the compiler does not need to know the length of the first dimension.
 
7. The C language converts multidimensional arrays into array pointers. The following 4 ways of expression are equivalent:
a[i][j];* (A[i] + j);(* (A + i)) [J];* (* (A + i) + j);
8 . Semantically, the subscript operator returns a reference to an element. For example, Statement 1 and statement 2 are equivalent:
Statement 1A[3] = 100;//statement 2int &ri = A[3];ri = 100;
9 . You cannot use a pointer of an element type to receive the return address of a dynamically created multidimensional array, because a multidimensional array is semantically not equivalent to a pointer to its element type, which is equivalent to a pointer to an array. For example, the following usage is correct:
Char *q = new Char[5];d elete []q; char (*P) [4] = new Char[5][4];d elete []p;
 
10, (1) label (lable) is the only identifier with a function scope. No matter what line the label defines in the function, the function is nested deep inside it, and it can be accessed anywhere in the function body. The label is generally used in a goto statement, which is ignored if the goto statement is not used for that label. 
(2) when the authority variable has the same name as a global variable, the global variable is obscured within the function. In this case, the global variables can be referenced within the function by a unary scope resolution operator, such as: A. 
The easy-to-ignore details of C language (fourth article)