"C-Language section"
First, the concept question:
1. What does static mean in C and C + + (language)parsing:1. Static main modifier variables, functions, member variables and member functions2, the modified variable indicates the life cycle of the variable, the life cycle with the process, the end of the process.3, modifier function, indicating that the scope of the function is limited to the use of this file4. Modifier member variables and member functions are only for C + +, and also represent the life cycle and scope5. Static modified variables are initialized to 0 by default6. Static modified variables will only be initialized once in the function.
2. What does const mean in C + + (language)parsing:1. Const can be used to modify variables in C/C + +, which is a read-only variable, modified in C + + is a constant2, can be modified function, in the C language to modify the function's return value, but in C + + can be decorated with the return value can also be decorated with the normal function3, the modifier pointer, placed in the * front repair pointer point to my value is constant, put in the * after the modifier pointer is a constant address4, modified parameters, to ensure that the value of the function is not changed
3. Volatile key role (language)parsing:1, volatile original meaning is variable, so it is generally used to modify variables to ensure that each value is taken from memory instead of in the register, the general comparison is used in multi-threading
4. The difference between New&delete and Malloc&freeparsing:1, new, and delete are the operators used by C + + for memory allocation and deallocation, and malloc and free are functions that the C language uses to allocate and free memory2, new and delete can generally use malloc and free as the underlying implementation, and new allocated memory does not need to display the computed size of the incoming, and malloc must and malloc return value of void*, Therefore, the space after the general application requires forced type conversion3, malloc bottom realization by mmap and BRK to achieve, large memory applications with mmap direct mapping to improve efficiency, small pieces of memory by BRK to allocate, can also be implemented with SBRK, but sbrk the bottom is also the brk,brk of the transfer is offset size, SBRK incoming address space that needs to be allocated4. New application space will adjust the constructor malloc will not, delete will be the destructor free does not5. New application space failure throws an exception, malloc request space failure returns null6, New has the locator new, and new can be overloaded by operator new
5, casually write a function pointer, array of pointers and arraysparsing:1, function pointer: int (*PTR) ();2. Array of pointers: int *ptr[];3. Array pointer: int (*PTR) []
6. Do you think the pointer and array are the same? Talk about the pointers you understand. parsing:1, certainly different, the pointer is a piece of address, and the allocation of the array in the stack space on a contiguous address, although they all refer to the address, but their meaning is different2, the pointer is divided into two pieces, one is the address of the pointer itself, the second is the pointer to the address, the pointer itself address is defined on the stack of the address, but this fast address can not village data, for example: int *p;p itself is the address on the stack, but can not use *p=10; And the pointer to the address can be on the stack can also be opened up on the heap,3, when the array function parameters will degenerate into a pointer
7. What is the difference between const and # define? parsing:1, const in C language is modified by read-only variables, in C + + is decorated with constants2. The const checks the type safety, #define只是在编译的时候进行宏替换
8. Explain to me how you understand the structure of the body to align. parsing:1, in the 32-bit operating system by default is 4-byte alignment, that is, if the variable type is less than 4, then the 4-bit, and finally in the calculation of the entire structure of the size of the results will also need to be an integer multiple of 4, if not the complement2, in order to improve the data read efficiency only to set the time-space method for memory alignment
9, compare strlen and sizeof. parsing:1, strlen is to find the size of the string, and the "\" end tag, and sizeof to find the size of the space, regardless of what type can be begged and strlen only suitable for the string2, strlen is a function, sizeof is an operator3, strlen in the run time to determine, sizeof in the compilation of the time to determine the4, sizeof only to find the current results, there will be no changes to the data, such as int i=10;sizeof (i++), the last I or equal to ten
Common face questions in C + +