1. What is the purpose of static? (Please specify at least two types)
1) In the function body, the variable declared as static does not change its value in the function call.
2) In the same file (but in the external body of the function), static variables can be accessed by all functions in this file, but cannot be accessed by other functions outside the module. It is a local global variable.
3) in a module, a function declared as static can only be called by other functions in the module. That is, this function is restricted to use within the local scope of the module that declares it.
2. What is the difference between reference (&) and pointer?
1) The reference must be initialized and the pointer is not required.
2) The reference cannot be changed after initialization. the pointer can change the object.
3) There is no reference pointing to a null value, but there is a pointer pointing to a null value.
4) The reference has no const, the pointer has const, And the pointer of const is immutable;
Appendix: Int & RA = A; // reference Ra, which is a reference of variable A, that is, alias
& Here is not an address calculation, but an identifier.
Declare the reference and initialize it at the same time.
After the declaration is passed, the variable has two names.
References do not occupy storage units.
Reference cannot be created, pointing to pointer reference (Int & N; Int & * P is the wrong int * & Q; correct)
3. Describe the basic features of the Real-Time System
Time Constraint
Predictability
Reliability
4. Are global variables and local variables different in memory? If so, what is the difference?
Global variables are stored in static databases.
Local variables are on the stack.
Local variables block global variables.
Global variables run faster (no need to allocate space)
5. What is a balanced binary tree?
Both left and right Subtrees are balanced binary trees, and the absolute value of the depth difference between left and right Subtrees is not greater than 1.
6. What causes stack overflow?
Writing too much data into the stack
7. What functions cannot be declared as virtual functions?
Common functions (non-member functions );
Static member functions;
Inline member functions;
Constructor;
Youyuan function.
Cause: Only member functions of the class can be declared as virtual functions.
A virtual function is used to execute only one function under multi-state conditions. During inheritance, you always need to first construct the parent class object and then subclass object. If the constructor is set to a virtual function, You have to display the call construction that you have to display when constructing the constructor of the parent class, another reason is to prevent errors. Imagine if you accidentally overwrite a function that is the same as the parent class constructor In the subclass, then the constructor of your parent class will be overwritten, that is, the parent class cannot be constructed. an error occurs.
Appendix: StatementVirtual function return value type virtual function name (parameter table)
You can redefine the virtual function in the derived class of the base class.
8. What is the time complexity of the bubble sort algorithm?
The time complexity is O (n ^ 2 ).
9. Write the if statement for comparing float X with "zero value.
If (x> 0.000001 & x <-0.000001)
Float is a floating point number and cannot be =. Use <and> to compare it with a number close to 0. The floating point is not precisely stored. Only one precision can be set.
10. What network protocol does the Internet use? What is the main hierarchy of the protocol?
TCP/IP protocol
The main layers are application layer, transmission layer, network layer, data link layer, and physical layer.
11. What protocol does the physical and IP address translation use for the Internet?
ARP (Address Resolution Protocol)
12. What are the two parts of IP address encoding?
Network number and host number.
However, it is only after bitwise AND with the "subnet mask" that we can distinguish which are the network bit and which are the host bit.
13. The user inputs the M and N values. The number of sequential loops starts from 1 to n. This value is output on every count to m until all are output. Write the C program.
Cyclic linked list, with the remainder operation
14. The parameter types that cannot be switched () are:
The switch can only contain int type or be converted to int type.
So you can put byte char short
Float double Long is not allowed.
Real-type variables (Real-type variables that can change their values during the running process are called real-type variables, that is, changing the accuracy.
Double, float)
15. The C ++ program consists of classes and functions. templates are also divided into class templates and function templates ).
The difference between a function template and a template function is:
A function template is a template definition that uses common type parameters.
A template function is a real function definition. It is generated by the compilation system when a specific function is called and has program code. Is to convert the template to the required type.
After a class template is described, you can create an instance of the class template to generate a template class.
16. How are pure virtual functions defined? What should I pay attention to when using it?
Virtual void F () = 0;
Yes, the subclass must be implemented
17. Differences between arrays and linked lists
Array: sequential data storage, fixed size
Linked List: data can be stored randomly and the size can be dynamically changed.
18. What is the layer-7 model of ISO? What layer does TCP/UDP belong? What are the advantages and disadvantages of TCP/UDP?
1) Application Layer
Presentation Layer
Session Layer
Transport Layer
Network Layer
Data Link Layer
Physical Layer
2) TCP/UDP belongs to the transport layer
3) The TCP Service provides data stream transmission, reliability, effective traffic control, full duplex operations, and Multiplexing technologies.
UDP does not provide reliable IP protocol mechanisms, flow control, and error recovery functions. Because UDP is relatively simple, the UDP header contains a few bytes, which consumes less than the TCP load.
TCP: provides stable transmission services with traffic control. The disadvantage is that the packet header is large and the redundancy is poor.
UDP: it does not provide stable services, with a small packet header and low overhead.
19. An array table is known, and a macro is used to define the number of elements in the data.
# Define ntbl
# Define ntbl (sizeof (table)/sizeof (Table [0])
20. What are the differences and connections between threads and processes? Does a thread have the same stack? Does the DLL have an independent stack?
1) The process is dead, but only a collection of resources. The real program execution is completed by threads. When the program starts, the operating system will help you create a main thread.
2) Each thread has its own stack.
3) Is there an independent stack in the DLL? It is difficult to answer this question, or is there a problem in the question itself. Because the DLL code is executed by some threads, only the thread has a stack,
If the DLL is called by a thread in EXE, does the DLL have its own independent stack? If the DLL is executed by a thread created by the DLL itself, does the DLL have an independent stack?
The above is about the stack. For the heap, if each dll has its own heap, it is best to delete it from the DLL if it is dynamically allocated from the DLL, if you allocate memory from the DLL and delete it in the EXE or another DLL, it is very likely that the program will crash.
21. What is the meaning of the keyword const?
Read-Only
Const int;
Int const A; // The first two functions are the same. A is a constant integer.
Const int * A; // pointer to the constant integer. The integer value cannot be modified, but the pointer can
Int * const A; // a constant pointer to an integer. Integer values can be modified, but pointers cannot be modified.
Int const * a const; // point to the constant pointer of a constant integer. The integer value cannot be modified, and the pointer cannot be modified.
Why do we need to pay so much attention to the keyword const?
1). The purpose of this parameter is to send useful information to the person who reads the code. If you spend a lot of time cleaning up the garbage left by others, you will soon learn to thank this excess information. (Of course, programmers who know how to use const seldom leave garbage to let others clean it up)
2). By attaching information to the optimizer, using the keyword const may produce more compact code.
3) the rational use of the keyword const can enable the compiler to naturally protect parameters that do not want to be changed and prevent them from being modified by unintentional code. In short, this can reduce the occurrence of bugs.
22. What is the meaning of the keyword volatile and three different examples are given.
Modify the variables accessed and modified by different threads to prevent the compiler from optimizing the code. The variable defined as volatile means that the variable may be unexpectedly changed, the compiler will not assume the value of this variable. Precisely, the optimizer must carefully re-read the value of this variable every time when using this variable, rather than using the backup stored in the register. The following are examples of volatile variables:
1). Hardware registers of parallel devices (for example, Status Registers)
2). Non-automatic variables that will be accessed in an interrupt service subroutine)
3) variables shared by several tasks in multi-threaded applications
People who cannot answer this question will not be hired. I think this is the most basic problem to distinguish between C programmers and embedded system programmers. Embedded System programmers often deal with hardware, interruptions, RTOS, and so on, all of which require volatile variables. If you do not know volatile content, it will lead to disasters.
If the subject correctly answers this question (well, I doubt this will happen), I will go a little deeper to see if this guy understands the full importance of volatile.
1) can a parameter be const or volatile? Explain why.
2) can a pointer be volatile? Explain why.
3) What are the following function errors:
Int square (volatile int * PTR)
{
Return * PTR ** PTR;
}
The answer is as follows:
1). Yes. One example is read-only status registers. It is volatile because it may be unexpectedly changed. It is const because the program should not try to modify it.
2). Yes. Although this is not very common. When a service subroutine repairs this pointer to a buffer.
3) This code has a prank. The purpose of this Code is to return the pointer * PTR points to the square of the value. However, since * PTR points to a volatile parameter, the compiler will generate code similar to the following:
Int square (volatile int * PTR)
{
Int A, B;
A = * PTR;
B = * PTR;
Return a * B;
}
* The value of * PTR may be unexpectedly changed, so a and B may be different. As a result, this Code may not return the expected square value! The correct code is as follows:
Long square (volatile int * PTR)
{
Int;
A = * PTR;
Return a *;
}
23. What is the problem with the for (; 1;) statement? What does it mean?
While (1) is the same.
24, do ...... While and while ...... What is the difference between do and do?
The previous cycle is judged again, and the last one is recycled later.
25. What is the difference between a queue and a stack?
Queue first-in-first-out; stack first-in-first-out
Queue, limited to insert at one end and delete at one end; stack limited to insert and delete at one end
26. For a frequently used short function, what implementation is used in C language and in C ++?
C is defined by macro, and C ++ is defined by inline (inline function)
27. How can I use two stacks to implement the function of a queue? Algorithms and ideas are required!
Set the two stacks to A and B. They are empty at the beginning.
Join:
Push new elements into stack;
Departure:
(1) judge whether stack B is empty;
(2) If it is null, all elements in stack a will pop out and push to stack B in sequence; otherwise, elements in stack B will pop up directly.
(3) pop the top element of stack B;
In this way, the complexity of queuing and queuing is still O (1), which is better than the above methods.
28. Is the Atool () function used to convert a character into an integer in the C language library function? What is the prototype of this function?
Function Name: atol
Function: converts a string to an integer.
Usage: Long atol (const char * nptr );
Program example:
# Include
# Include
Int main (void)
{
Long L;
Char * STR = "98765432 ";
L = atol (lstr );
Printf ("string = % s integer = % LD \ n", STR, L );
Return (0 );
}
30. Can a local variable be renamed with a global variable?
A: Yes. Global blocking will be performed in some cases. To use global variables, you must use "::"
A local variable can have the same name as a global variable. A local variable with the same name is used when this variable is referenced in a function, instead of a global variable. For some compilers, multiple local variables with the same name can be defined in the same function. For example, a local variable with the same name can be defined in both loops, the scope of the local variable is in that loop.
31. How do I reference a defined global variable?
1) extern
2) Reference header files
Difference: Use the reference header file to reference the global variables in the header file. If you write the variable wrong, an error will be reported during compilation. If you reference the variable using the extern method, if you make the same mistake, no error will be reported during compilation, but an error will be reported during connection.
32. Can global variables be defined in header files that can be contained by multiple. c files? Why?
Yes. The global variables with the same name are declared in static form in different C files.
The premise is that only one C file can assign an initial value to this variable, and the connection will not fail.
33. What is a group of links that directly link two signaling points?
PPP point-to-point connection
34. Differences between heap and stack.
Heap is a stack, and stack is a stack.
Stack space is automatically allocated/released by the operating system, and heap space is manually allocated/released.
Stack space is limited, and heap is a large free storage zone.
The memory allocated by the malloc function in C is on the heap, and the c ++ corresponds to the new operator.
During the compilation period, the program implements both the variable and function allocation memory on the stack, and the parameter transfer is also performed on the stack when the function is called during the program running.
35. What is the difference between the C ++ class and the struct in C?
In C ++: A member function can be created. The default value is private. The struct is public by default.
There can be inheritance, virtual functions, and polymorphism.
C: Only variables
36. What are the usage and functions of destructor and virtual functions?
A destructor is also a special class member function. It does not return a type, has no parameters, cannot be called at will, and is not overloaded. When the life cycle of a Class Object ends, the system automatically calls and releases the resources allocated in the constructor. During running, the ability to call that function can be determined based on its type is called polymorphism, or later Association. In addition, destructor usually finish the work before the object is undo, such as memory reclaim.
The function of a virtual function is to enable the subclass to overload the parent function with functions of the same name, and automatically call the subclass overload function when calling the function. If it is a pure virtual function, this is simply to have a uniform name when the subclass is overloaded.
46. Could you explain in detail the definition of the IP protocol? At which layer, what is the main role? What about TCP and UDP?
UDP, TCP at the transmission layer, IP at the network layer, TCP/IP is the abbreviation of English Transmission Control Protocol/Internet Protocol, meaning "Transport Control Protocol/Internet Protocol ". TCP/IP protocol groups are popular in part because they can be used on a variety of channels and underlying protocols (such as T1 and X.25, Ethernet, and RS-232 serial interfaces. Specifically, the TCP/IP protocol is a group
User datainprotocol, ICMP (Internet Control Message Protocol), and other protocols. The TCP/IP protocol does not fully comply with the OSI Layer-7 Reference Model. The traditional Open System Interconnection Reference Model is a layer-7 abstract reference model of communication protocols, where each layer executes a specific task. This model aims to make various hardware communicate with each other at the same level. These seven layers are: physical layer, data link layer, network layer, transmission layer, voice layer, presentation layer and application layer. The TCP/IP communication protocol uses a layer-4 hierarchy. Each layer calls the network provided by its next layer to meet its own needs. This
The four layers are:
Application Layer: layer for communications between applications, such as simple Email transmission (SMTP), file transfer protocol (FTP), and network remote access protocol (Telnet.
Transport Layer: In this layer, it provides data transmission services between nodes, such as transmission control protocol (TCP) and User Datagram Protocol (UDP, TCP and UDP add transmitted data to the data packet and transmit it to the next layer. This layer is responsible for transmitting data and confirming that the data has been delivered and received.
Interconnect Network Layer: provides basic data packet transmission functions so that each data packet can reach the target host (but does not check whether it is correctly received), such as Internet Protocol (IP ).
Network Interface Layer: manages the actual network media and defines how to transmit data using the actual network (such as Ethernet and serial line.