当前位置:网站首页>C language interview preparation I (about understanding Department)
C language interview preparation I (about understanding Department)
2022-07-29 07:56:00 【A tong Muyou】
1. How to understand c Language is a structured language ( understand c Language )
c Language is a compiled language , Its grammar is concise , Rich functions , Flexible use . Altogether 32 Keywords ,9 Control statements
Common keywords :
Common control statements :
1. Excellent portability :
2. Direct access to hardware :
1) By writing data to memory space , The hardware maps registers to memory addresses , Access the hardware directly by operating the address in memory .
2) I usually write code in protected mode , The accessible memory address is limited . Unable to access hardware mapping address .
3. With high-performance operation efficiency :
Precise control of each byte , The compiler does not have too many additional elements , Compile directly .
Talk about c Basic unit functions of language
The concept of function :
yes c The basic unit of a program , Returned by , Function name , Function parameter , The body of the function , There are four main parts .
1. The definition of function is relatively independent ( Can be defined anywhere outside the function ), The program always starts with the main function .
2. Modular programming that can be invoked and executed from other parts of the program (c Language is structure oriented )
characteristic :
1. A function can only have one return value2. A program can have one or more functions nested , But you can't nest definitions
3. Modularize the program , Make the program more concise , Increase readability .
Function call
step :
1. Find the entry address of the function through the function name , The address of the next instruction calling the function statement in the stack pressing main function .
2. Allocate space for formal parameters , Pass the value to the space corresponding to the formal parameter , Stack the formal parameters from right to left , Then there are local variables in the function
3. Execute the function body statement
4. Function return value , And free the function space .
expenses :
1. Parameter stack
2. The program counter points to the called function ( Control moves to function )
3. Create a new stack frame ( Open up new space on the stack ), use ebp Value identifies the new stack frame , And save the original stack frame address .
4. Restore the original stack frame , Control moves to the caller
Corresponding c++ Inline functions in and preprocessing #define
When the inline function is compiled, it is expanded when the function is called , Do not create new stack frames , Save the time cost of entering and leaving the stack .
#define: Perform plain text replacement during preprocessing , There is no error detection function. Pay attention to the boundary conditions .
key word
static
Definition : It's a key word .
stay c Only variables can be modified in language , Its decorated variables are assigned to the static area when the program is run and defined .
stay c++ Member functions can be modified in , The class members it modifies must be initialized and outside the class . The decorated class member function does not this The pointer , Class members cannot be called , Only static data can be called .
1. Modify local variables : Not initialized. The default is 0: Put it in .bss paragraph , Initialized to put .data paragraph
General local variables are in the stack area , Release at the end of the function call ,static Decorated local variables are allocated in the static area , Release... At the end of the program , The delay has a long life cycle , But the scope is still limited to statement blocks .2. Modify global variable : Not initialized. The default is 0: Put it in .bss paragraph , Initialized to put .data paragraph
The scope is limited to be visible in this source file , Not visible in other documents of the project .
extern: It extends the scope of global variables and functions, which can be seen in other files of the project .
const
Definition : It's a key word
c In language
const Modify the value of local variables as read-only and cannot be modified , But the memory extended by its value can be modified .
General global variables are in the static area ,const When modifying global variables , Store the global variables in the constant area .
c++ in
const Decorated variables are stored in a symbol table in the stack area , One by one correspondence with data through key value pairs .
auto Local variables allocated in stack space .
register
stay c In language , Modifying variables , Refers to a variable that directly references a register , Operation on variable name , It is equivalent to accessing registers , Declared register variables are not necessarily stored in registers .
1. The declaration type should be the type that the register can receive , The variable length should be less than the register length
2. Cannot address a register variable .
stay c++ in , You can take the address , but regitser Keywords become invalid , The defined variables will be put into memory .
volatile
Decorated variable , The compiler no longer optimizes , Every time I have to access variables in memory
Usually used for :
1. When modifying other program variables in the interrupt service program, add volatile
2. Multi task shared flag bit plus volatile.
3. Memory mapped hardware registers plus volatile.
Principle and essence :
When a thread is reading data in memory , Will first put the data and its address 64KB The data of is cached in the register .
When modifying the value of a variable in this thread, first modify the value in the register and then copy it to memory .
When other threads modify the value in memory , It will cause inconsistency between memory and register data .
typedef And #define difference
The principle is different :
typedef Is the key word , Process at compile time and only once , Can carry out type error detection .
#define It's preprocessing instructions , In pretreatment , Replace each call with plain text , No error detection , Error in compiling the developed open source program .
Different functions :
typedef: Alias an existing type , Only type
#define: Not just types . Constant , Variable , Compile switch, etc ...
Different scopes
typedef: Only in this source file
#define: There are no scope restrictions , Available after definition .
The operation of the pointer is different ( Alias based on a type , One is plain text substitution )
typedef: const typedef p; const Modification is typedef The type of embellishment
The difference between a structure and a consortium
struct It's a keyword , You cannot define yourself within yourself .
stay c Language is a collection of data types , Improper processing of new data types :
1. When defining, add struct.
2. You cannot define a function in a structure .
stay c++ Is a new data type .
1. You can assign values directly with structures
2. You can define functions in the structure , The default is public space (class Default private )
Examination site ( Byte alignment ):
1.cpu Fixed byte addressing , Avoid meaningless multiple addressing variables , Byte alignment required .
2. Align according to the maximum of the self alignment values of all data types .(int a[10] The alignment value type is int, The space occupied is 40)
3. Align the specified alignment value with the minimum of the maximum alignment value of the data type .(#pragma(value)).
union Is a key value, all data share a piece of memory , Its size is The maximum length of each member .
Examination site ( Member coverage ):
Cannot load multiple members at the same time , There is only one member variable at a time , The new member variable assignment will overwrite the old member .
Operator priority and combination rate
1. The equality operator is greater than the bitwise operator > Logical operators > Assignment operator is only greater than comma operator
2.(. Member selection )>(++ Self increasing )>(* Take the content )
++,(=) The combination rate of assignment is from right to left
边栏推荐
- Data unit: bit, byte, word, word length
- 10 common software architecture modes
- The difference between static library and dynamic library of program
- Very practical shell and shellcheck
- Access数据库引入datagridview数据后,显示错误
- In the MySQL connector of flynk CDC, the MySQL field is varbinary, which is officially
- Jianmu continuous integration platform v2.5.2 release
- Go, how to become a gopher, and find work related to go language in 7 days, Part 1
- Greenplus enterprise deployment
- 佳木斯市场监管局开展防疫防虫害专题食品安全网络培训
猜你喜欢
mysql 使用 DATE_FORMAT(date,'%Y-%m')
Solving linear programming problems based on MATLAB
[deep learning] data preparation -pytorch custom image segmentation data set loading
Go, how to become a gopher, and find work related to go language in 7 days, Part 1
Monitor the bottom button of page scrolling position positioning (including the solution that page initialization positioning does not take effect on mouse sliding)
How to draw an excellent architecture diagram
监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)
黑盒测试常见错误类型说明及解决方法有哪些?
Cs61abc sharing session (VI) detailed explanation of program input and output - standard input and output, file, device, EOF, command line parameters
Pat class a 1146 topology sequence
随机推荐
Day 014 2D array exercise
MySQL 45 讲 | 07 行锁功过:怎么减少行锁对性能的影响?
下推分析的限制
Pat class a 1154 vertex shading
Solve the problem that CSDN cannot publish blog due to unknown copyright
[introduction to cryoelectron microscopy] Caltech open class course notes part 3:image formation
[skill accumulation] presentation practical skill accumulation, common sentence patterns
LVM logical volume group management
FLink CDC 的mysql connector中,mysql的字段是varbinary, 官方
[cryoelectron microscope] relation4.0 - subtomogram tutorial
Ionicons icon Encyclopedia
Mutationobserver document learning
《nlp入门+实战:第五章:使用pytorch中的API实现线性回归》
Limitations of push down analysis
Jump from mapper interface to mapping file XML in idea
MySQL 45讲 | 08 事务到底是隔离的还是不隔离的?
[note] the art of research (understand the importance of the problem)
智慧城市的应用挑战,昇腾AI给出了新解法
MySQL 45 | 08 is the transaction isolated or not?
Prepare esp32 environment