C + + conceptual summary

Time:2021-4-12

1. What is the idea of object-oriented programming?

A: the data structure and the method of operating the data structureencapsulationForm objects one by one.

2. What is class?

Answer: classify some common objects to form a collection, which is called class.

3. What are the two characteristics of objects? What do they mean?

A: the characteristics of the objects are as follows:static stateFeatures anddynamicfeatures.

Static characteristicsIt refers to some properties that can describe an object.

Dynamic characteristicsIt refers to the behavior of the object.

4. What is the significance of declaring a class in the header file and defining a class in the corresponding implementation file?

A: 1Improve compilation efficiencyBecause if the class is separated, it only needs to be compiled once. After generating the corresponding. Obj file, the class will not be compiled again where it is applied again, which greatly improves the efficiency.

        2.The code is hidden

5. Define the function body of the member function inside the class. What kind of attributes does this function have?

A: this function will automaticallyInline functionThis functionfunction callCode replacement will be carried out during the compilation phase.

6. What do member functions use to distinguish member data of different objects? Why can it be distinguished?

A: Yesthis pointer Because it points to the objectFirst address

7. What are the four default functions automatically generated by the C + + compiler for classes?

A:defaultConstructors (constructors without arguments),CopyConstructors (for assignments between objects),DeconstructionFunction,assignmentFunction (assignment of equal sign).

8. Under what circumstances will the copy constructor be called?

Answer: 1. When an object of a class is initializedThis categoryAnother object of.

2. If the formal parameter of a function is an object of a class, call the function to combine the formal parameter with the actual parameter.

3. If the return value of the function is a class object, when the function call completes the return.

9. What is the difference between constructor and ordinary function in form? (the function of the constructor, its declaration form to analyze)

A: a constructor is a special member function of a class. In general, it is used to initialize object member variables.

The name of the constructor must beSame as class name, which has no type and returns no value.

10. When do I have to override the copy constructor?

A: when the constructor involvesDynamic storage allocationWrite your own copy constructor and make a deep copy.

11. What is the calling order of constructors?

Answer: 1. Call the base class constructor first

2. Initialize data members in declaration order

3. finally, call your own constructor.

12. In which cases must the initialization member list be used?

A: 1. Class members are constant members.

Object is a member of the classNo,Parameterless constructor.

3. When a member of a class is a constant variable.

13. What is a constant object?

Answer: constant object refers to the object whose member value cannot be modified in any situation.

14. What is the meaning of static function?

A: 1Out of classIt can not be accessed, but can be accessed through the static member function of the class;

2. When a class’s constructor is private, it doesn’t instantiate itself like a normal class, so it can only call the constructor through a static member function.

15. Is there any way to access the non-public members of a class outside the class?

A: friend, inheritance, public member function.

16. What is abstract class?

A: it is not used to define objects, but as a basic typeInherited classes

17. What is the meaning of operator overloading?

A: in order to make the operation of data of user-defined data type consistent with the operation form of data of internal defined data type.

18. What are the five operators that are not allowed to be overloaded?

Answer: 1.. * (member pointer access operation symbol)

2.:: field operator

3. Sizeof length operation symbol

4.? : conditional operation symbol

5. (member accessor)

19. Three ways of operator overloading?

A: ordinary function, friend function, class member function.

20. Why can’t stream operators be overloaded by class member functions? How to solve this problem?

Answer: because the member function overload of the class must be the first operatorownThe overload of convection operation requires that the first parameter beStream object. It is usually solved by friends.

21. The difference and relation between assignment operator and copy constructor?

A: the same point: they all copy one object to another.

Difference: the copy constructor involves creating a new object.

22. In which case do you want to call the destructor of this class?

A: at the end of the object life cycle.

23. How to share data among objects?

Answer: it is implemented through the static member variable of the class. Static member variables occupy their own independent space and are not private to an object.

24. What are the characteristics of friendship?

A: unidirectional, non transitive and non inheritable.

25. What is the initialization order of object members?

A: its order is not affected by their order in the initialization table at all. It is only related to the member objects in the classOrder of declarationIt’s up to you.

26. What is the relationship between class and object?

A: classes are objectsabstractObject is of classexample

27. What are the access properties for members of a class?

A: public, protected, private.

28. What is the difference between const char * P and char * const p?

A: if const is on the left side of the asterisk, const is used to modify the variable that the pointer points to, that is, the pointer points to a constant;

If const is to the right of the asterisk, const modifies the pointer itself, that is, the pointer itself is a constant.

29. Is it true that a parent class writes a virtual function, and if the subclass covers its function without adding virtual, it can also achieve polymorphism?

A: the virtual modifier will be inherited implicitly.

Virtual can be added or not. The functions covered by subclasses can be polymorphic without adding virtual.

30. What does function overload mean? What is the difference between it and the concept of virtual function?

A: function overload is a function with the same name to complete different functions. The compiler system realizes static polymorphism through the number and type of function parameters in the compilation phase. But remember: you can’t overload a function just by having different return values.

Virtual function is to declare a function as a virtual function by using the keyword virtual in the base class, which means that the function may be defined in the future derived class or extended on the basis of the base class. The system can only dynamically determine which function to call in the run-time, so the implementation isDynamic polymorphism. It embodies a vertical concept, that is, between base class and derived class.

31. Can constructors and destructors be overloaded? Why?

A: constructors can be overloaded, destructors can’t be overloaded.

Because the constructor can have more than one and can take parameters, while the destructor can only have one and can’t take parameters.

32. How to define and implement a member function of a class as a callback function?

A: the so-called callback function isbeforehandRegister the function in the system to let the system know the existence of the function. Later, when an event occurs, call the function to respond to the event.

When defining a member function of a class, prefix the function nameCALLBACKThat is to say, it is defined as a callback function, and its implementation is no different from ordinary member functions

33. How is the virtual function realized?

A: in short, we use the virtual function table

34. Abstract classes do not produce instances, but they also need constructors. 

35. From a template class, you can derive a new template class or a non template class.

36. What code will be executed before the main function is executed?

answer:Global objectsIs executed before the main function.

37. When a Class A does not have any member variables or member functions, what is the value of sizeof (a). If it is not zero, please explain why the compiler does not make it zero. (Autodesk)

Answer: definitely not zero.

For example, if it is zero, declare an array of class a [10] objects, and the space occupied by each object is zero, then it is impossible to distinguish a [0] from a [1].

38. What’s the difference between delete and delete?

A: delete only calls the destructor once, while delete [] calls the destructor of each member.

39. Do you want to call the parent class’s destructor when the subclass is destructed?

A: Yes. The order of destructor calls is to destruct the derived class first and then the base class. That is to say, when the base class is destructed, all the information of the derived class has been destroyed

**************************************************************************

40. Advantages and disadvantages of inheritance:

advantage:

1. Class inheritance is statically defined at compile time and can be used directly,

2. Class inheritance can easily change the implementation of parent class.

Disadvantages:

1. Because inheritance is defined at compile time, it cannot be defined at compile timeruntimeChanging the implementation of inheritance from a parent class

2. The parent class usually defines at least part of the behavior of the subclass, and any change of the parent class may affect the behavior of the subclass

3. If the inherited implementation is not suitable for solving the new problem, the parent class must be overridden or replaced by another more suitable class. This dependency limits flexibility and ultimately reusability.

41. Explain the difference between heap and stack

1. Stack – automatically allocated and released by the compiler, storing function parameter values, local variable values, etc.

2. Heap: it is usually allocated and released by the programmer. If the programmer does not release it, it may be recycled by the OS at the end of the program.

42. When are the constructors and destructors of a class called? Do they need to be called manually?

A: constructors are automatically called when creating class objects, and destructors are automatically called by the system at the end of class objects’ lifetime.

43. When to precompile:

1. A large code body that is always used and not often changed.

2. The program consists of several modules, all of which use a set of standard include files and the same compilation options. In this case, all included files can be precompiled into a precompiled header.

44. The role of polymorphism?

There are two main problems

1. Hide the implementation details to make the code modularized; extend the code module to achieve code reuse; 2;

2. Interface reuse: to ensure the correct call when using a property of any class instance in the family when the class inherits and derives

45. What’s the difference between virtual function and ordinary member function? Can inline functions and constructors be virtual functions?

A: 1. Virtual function has virtual keyword, virtual pointer and virtual function table. Virtual pointer is the interface of virtual function, but ordinary member function does not.

2. Inline functions and constructors cannot be virtual functions.

46. The calling order of constructors and destructors? Why should destructors be virtual?

The calling order of constructors: base class constructors – object member constructors – derived class constructors; the calling order of destructors is opposite to constructors.

2. Destructor virtualization is to prevent memory leakage caused by incomplete destructor.

47. Which functions can access member variables of type private in C + +?

It can only be accessed by member functions and friend functions in this class

48. Please tell us the differences among the three types of access restrictions: private, protected and public

1. Private is a private type, which can only be accessed by member functions in this class.

2. Protect is protected, which can be accessed by this class and inheritance class.

3. Public is a public type, which can be accessed by any class.

49. How to initialize member variables in a class?

It can be implemented through the initialization list of the constructor or the function body of the constructor.

50. When do I need to use “frequently quoted”?

If we want to use reference to improve the efficiency of the program and protect the data passed to the function from being changed in the function, we should use frequent reference.

51. What’s the difference between a reference and a pointer?

A: 1. The reference must be initialized, and the pointer does not have to be initialized.

2. The reference cannot be changed after initialization. The pointer can change the object it refers to.

3. There is no reference to null value, but there is a pointer to null value.

52. Describe the basic characteristics of real-time system

In a specific time to complete a specific task, real-time and reliability.

54. Are there any differences between global variables and local variables in memory? If so, what is the difference?

A. global variables are stored in the static data area, and local variables are stored in the stack.

55. What causes stack overflow?

A. there is no recycling resource

56. What functions cannot be declared virtual?

A: constructor

57. What are the two parts of IP address coding?

Answer IP address consists of two parts, network number and host number.

58. The parameter types that cannot switch() are:

A. the switch parameter cannot be real.

59. How to reference a defined global variable?

A. you can refer to the header file or use the extern keyword.

If you refer to a global variable declared in the header file by referring to the header file, if you write that variable wrong, an error will be reported during compilation. If you refer to it by using extern, if you make the same error, an error will not be reported during compilation, but during connection.

60. For a frequently used short function, what implementation should be applied in C language and C + +?

A. C is defined by macro and C + + by inline.

61. Is C + + type safe?

Answer: No. Two pointers of different types can be cast (using reinterpret cast)

63. Briefly describe the difference between array and pointer?

1. Arrays are created either in static storage (such as global arrays) or on the stack.

2. The pointer can point to any type of memory block at any time.

(1) Differences in content

char a[] = “hello”;

a[0] = ‘X’;

Char * P = “world”; / / note that P points to a constant string

P [0] =’x ‘; / / the compiler can’t find the error, run time error (* *

(2) The sizeof operator can be used to calculate the capacity (number of bytes) of an array. Sizeof (P), where p is the number of bytes of a pointer variable, not the memory capacity referred to by P.

The transfer method of value in 64. C + + function

There are three ways: value passing, pointer passing and reference passing.

65. Memory allocation

There are three ways of distribution

1. Static storage area, which has been allocated at the time of program compilation, exists during the whole running period, such as global variables and constants.

2. The local variables in the function are allocated from the stack, but the allocated memory is easy to be limited.

3. Heap allocation is also called dynamic allocation. For example, we use new and malloc to allocate memory and delete and free to free memory.

66. What is the function of extern “C”?

Extern “C” is a connection exchange symbol provided by C + +, which is used to tell C + + that this code is a C function.

This is because after C + + is compiled, the function name in the library will become very long, which is inconsistent with that generated by C. as a result, C + + can not directly call C functions. With the addition of extend “C”, C + + can directly call C functions.

Extern “C” mainly uses the reference and export of regular DLL functions and is used when C + + contains C functions or C header files. When using, you can add the keyword “external” C “in front of it.

67. What functions are used to open new processes and threads.

A: 1. Thread: create thread / afxbeginthread, etc.

2. Process: create process, etc.

68. What is the difference between SendMessage and PostMessage?

Answer: 1. SendMessage is blocked. After the message is processed, the code can go to the next line of SendMessage.

2. PostMessage is non blocking, no matter whether the message has been processed or not, the code will immediately go to the next line of PostMessage.

69. What are the main functions of cmemorystate?

A: check the memory usage and solve the problem of memory leakage.

What is the difference between “70.26”, “include” and “file name. H”?

Answer: 1. For # include, the compiler searches for file name. H from the standard library path

2. For # include “file name. H”, the compiler searches for file name. H from the user’s working path

71. What is the purpose of processor identification error?

A: an error message will be output at compile time, and the compilation will be stopped.

72.#if!defined(AFX_…_HADE_H)

#define(AFX_…_HADE_H)

……

#What is the role of ENDIF?

Prevent the header file from being repeatedly referenced.

73. What should we pay attention to when defining a macro?

Answer: each parameter in the definition section and the entire expression must bebracketsTo avoid unforeseen errors.

74. What type does an array change when it is used as a function argument?

A: arrays become pointer types when they are used as arguments.

75. What are the three standard files that the system will automatically open and close?

(1) Standard input keyboard stdin

(2) Standard output — display — stdout

(3) Standard error output — display — stderr

How many bits are char, int, float and double in Win32?

(1) Char takes 8 bits (1 byte)

(2) Int occupies 32 bits (4 bytes)

(3) Float occupies 32 bits (4 bytes)

(4) Double takes 64 bits (8 bytes)

77. What is the difference between strcpy() and memcpy()?

A: both strcpy() and memcpy() can be used to copy strings. The copy of strcpy() ends with ”, but memcpy() must specify the length of the copy.

78. Explain the difference between define and const in grammar and meaning?

(1) #define is a method of defining symbolic variables in C syntax. Symbolic constants are only used to express a value. In the compilation stage, symbols are replaced by values. It has no type;

(2) Const is a method to define constant variable in C + + syntax. Constant variable has variable property, it has type, there is a storage unit named after it in memory, and the length can be measured by sizeof.

79. Tell the difference between character constant and string constant, and use the operator sizeof to calculate?

A: the character constant refers to a single character, the string constant ends with ”, and the operator sizeof is used to calculate the storage space of more than one byte.

80. What are the advantages and disadvantages of global variables?

A: global variable is also called external variable. It is a variable defined outside the function. It belongs to a source program file. It saves the last modified value, which is convenient for data sharing, but inconvenient for management, and easy to cause unexpected errors.

81. Summarize the application and function of static? (**************************)

(1) The scope of the static variable in the function body is the function body, which is different from the auto variable. The memory of the variable is allocated only once, so its value will remain the last value in the next call;

 

void fun1()

{

    static int a = 0;

    int b = 0;

    int sum_a= 0;

    sum_a = sum_a + a++;

    int sum_b = 0;

    sum_b =sum_b + b++;

    cout << sum_a << "" << sum_b << endl;

}

int main(int argc, char* argv[])

{

    int i = 0;

    while( i < 10 )

    {

        fun1();

        i++;

    }

    return 0;

}          

  

In this example, sum_ A is always accumulating. And sum_ B has always been zero

(2) The static global variables in the module can be accessed by the functions used in the module, but not by other functions outside the module;

(3) the first mock exam static function in the module can be called by other functions in this module, which is restricted to the module of its declaration.

(4) The static member variable in the class belongs to the whole class, and there is only one copy of all objects in the class;

(5) The static member function in the class belongs to the whole class. This function does not receive this pointer, so it can only access the static member variable of the class.

82. Summarize the application and function of const? (**************************)

(1) To prevent a variable from being changed, use the const keyword. When defining the const variable, you usually need to initialize it, because there is no chance to change it later;

(2) For a pointer, you can specify that the pointer itself is const, the data the pointer refers to is const, or both are const;

(3) In a function declaration, const can modify a formal parameter to indicate that it is an input parameter and its value cannot be changed inside the function;

(4) For a member function of a class, if it is of const type, it means that it is a constant function and cannot modify the member variables of the class_ name() const {}

(5) For a member function of a class, it is sometimes necessary to specify its return value as const type, so that its return value is not “lvalue”. const void fun_ name() {}

83. What is a pointer? What’s your understanding of pointer?

A: 1. Pointer is a variable, which is used to store memory address.

2. The type of pointer variable depends on the data type it points to. Add the*

3. The characteristic of pointer variable is that it can access the memory it points to.

84. What is a constant pointer and what is a pointer to a constant variable?

Answer: 1. The meaning of constant pointer is that the address pointed to by the pointer cannot be changed, but the content pointed to by the address can be changed. Using constant pointer can ensure that our pointer cannot point to other variables.

2. A pointer to a constant variable means that the address of the variable itself of the pointer can be changed and it can point to other variables, but the content it refers to cannot be modified.

85. The difference between function pointer and pointer function?

A: 1. A function pointer is a pointer to a function entry.

2. Pointer function means that the return value of function is a pointer type.

87. What’s the difference between debug and release?

The debug version is the debug version, and the release version is the final non debug version released to users.

88. Several typical applications of pointer?

Int * P [n]; — pointer array, each element is a pointer to integer data.

Int (*) P [n]; — P is a pointer to one-dimensional array, which has n integer data.

Int (* P) [n]; correct definition of array pointer.

//There’s a mistake here!!! int (*p)[n]????????

Int * p(); — function returns a pointer to the returned value.

Int (*) P (); — – P is a pointer to a function.

//Here’s the row and column pointer.

int main(int argc, char* argv[])

{

    int c[2][4];

    c[0][0] = 1;

    c[0][1] = 2;

    c[0][2] = 3;

    c[0][3] = 4;

    c[1][0] = 5;

    c[1][1] = 6;

    c[1][2] = 7;

    c[1][3] = 8;

    Int (* P) [4] = C + 0; // C + 0 is the row pointer! Define a row pointer int (* P) [n],

    //Int * P1 = C + 1; // an error will be reported here. : cannot convert from 'int (*)[4]' to 'int *'

    Int * PA = * C + 1; // * C + 1 represents the column pointer.!

    return 0;

}

  

//On the concept of function pointer.

void myfun( int a, int b)

{

    int c = 0;

    int d = 0;

    cout << "sdfsd" << endl;

}

void myfun1( int a, int b)

{

    int c = 0;

    int d = 0;

    cout << "sdfsd" << endl;

}typedef void (*PMYFUN)( int a, int b );

Pmyfun ifxn; // define a variable with this new type!

int main(int argc, char* argv[])

{

    Ifxn = myfun; // assign a value to the pointer variable to indicate which function it points to.

    iFxn(2, 3);

    iFxn = myfun1;

    Ifxn (32, 3); // y remove the specific function with pointer.

    return 0;

}

  

//On the concept of function pointer.

On the concept of function pointer. This pthreadproc can be understood as a new type, except that it is a pointer.

Pthreadproc pfun1; / / the variable defined with pthreadproc is a pointer.

Pfun1 = myfun; / / this is the core code, which will indicate which function is called.

current read

89. What is the difference between static function and ordinary function?

Static functions have only one copy in memory, while ordinary functions maintain one copy in each called function

90. What’s the difference between structure and union?

A: 1. Structure and union are composed of multiple members of different data types, but at any one time, only one selected member is stored in the Union (all members share a common address space), while all members of the structure exist (different members have different storage addresses).

2. For different members of the union, the values of other members will be rewritten, and the values of the original members will not exist, but for different members of the structure, the values will not affect each other.

91. What’s the difference between class and struct?

A: struct members are public by default, while class members are private by default.

92. Brief description of enumeration types?

A: it’s convenient to define a group of constants at a time, which is very convenient to use;

93. The function of assert()?

Answer: assert () is a macro that is often used when debugging programs. When the program is running, it calculates the expression in brackets. If the expression is false (0), the program will report an error and terminate execution. If the expression is not 0, the following statements continue. This macro is usually used to determine whether there is obviously illegal data in the program. If there is termination of the program, it will not lead to serious consequences, but also easy to find errors.

94. Can local variables and global variables have the same name?

A: Yes, the part will shield the whole. To use global variables, you need to use ‘:’ (field operator).

95. The local variables of the program exist in (stack), the global variables exist in (static area), and the dynamic application data exist in (heap).

96. When to use it?

A: if you want to use reference to improve the efficiency of the program and protect the data passed to the function from being changed in the function, you should use frequent reference.

97. What are the benefits of separating class declaration from implementation?

1. It has a protective effect;

2. Improve the efficiency of compilation.

What are the components of 98. Windows message system?

It consists of the following three parts:

1. Message queue: the operating system is responsible for maintaining a message queue for the process, and the program continuously obtains and processes messages from the message queue.

2. Message loop: the application continuously obtains and processes messages through message loop.

3. Message processing: the message loop is responsible for sending messages to related windows and using the associated window procedure function for processing.

99. What is message mapping?

Message mapping is to let the programmer specify MFC class (a class with message processing ability) to process a message. Then the programmer completes the writing of the processing function to realize the message processing function.

100. What is UDP and what is the difference between TCP?

The full name of TCP is transmission control protocol. This protocol can provide connection oriented, reliable, point-to-point communication.

UDP is fully known as user message protocol, which can provide non connection and unreliable point to multipoint communication.

With TCP or UDP, it depends on which aspect your program focuses on? Reliable or fast?

101. The main implementation steps of Winsock connection?

Answer: 1. Server side: socket() establishes a socket, binds and listens, and uses accept() to wait for the client to connect. When accept() finds that there is a client connection, it establishes a new socket and starts waiting for the connection again. The newly generated socket uses send() and recv() to write and read data until the data exchange is completed, and closesocket() closes the socket.

2. Client: socket() establishes a socket, connects to the server, and then uses send() and recv() to write and read data on the socket until the data exchange is completed, and closesocket() closes the socket.

102. What are the main communication methods between processes?

A: semaphores, pipes, messages, shared memory

103. What are the three dynamic link libraries that make up the functions of the Win32 API?

A: kernel library, user interface management library, graphical device interface library.

104. What are the steps to create a window?

A: fill in a window class structure, register the window class, create a window, display a window, and update a window.

105. What is the difference between modal and non modal dialog boxes?

A: 1. Different calling rules: the former is called with domodal(), while the latter is displayed by attributes and showwindow().

2. Before the modal dialog box is closed, the user can’t do other operations, but the non modal dialog box can.

3. When creating a non modal dialog box, you must write your own common constructor and call the create() function.

106. Take the data from the edit box to the associated variable. What is the function that has displayed the data of the associated variable on the edit box?

Answer: take out the update data (true) and display the update data (false)

107. A brief introduction to GDI?

GDI is the abbreviation of graphics device interface, translated as: graphics device interface; it is a function library which is implemented in Windows application program and has nothing to do with the device. These functions produce graphics and text output on different output devices.

108. What are the types of windows messages? And make a simple description of all kinds.

1. Window messages: messages related to windows, except WM_ All commands except command are WM_ The beginning of the message;

For user requests, 2_ The message indicated by command;

3. Control notification message: unified by WM_ Notift said,

4. User defined message.

109. How to customize messages?

Using WM_ User and WM_ App uses two macros to customize messages,

110. Describe the relationship between visual c + +, Win32 API and MFC?

(1) Visual C + is an integrated and visual programming environment based on C + + programming language;

(2) Win32 API is a set of application program interfaces provided by 32-bit windows operating system in the form of C / C +;

(3) MFC encapsulates the Win32 API, which simplifies the development process.

111. How to eliminate ambiguity in multiple inheritance?

1. Member qualifier

2. Virtual base class

What is static correlation and what is dynamic correlation

In polymorphism, if the program can determine the actual execution action in the compilation phase, it is called static Association,

If you wait for the program to run, it is called dynamic association.

Two necessary conditions for 113 polymorphism

1. A pointer or reference to a base class points to a derived class object,

2. Virtual function

114. What is a smart pointer?(*****************************************)

A: when there is a pointer to another class object in a class, overload the pointer operator, then the current class object can call the member of another class as its own member.

115. When do I need to use virtual destructors?

A: when the base class pointer points to the derived class object generated by the new operator, when the base class pointer is deleted, the derived class part is not released, resulting in incomplete release, which requires a virtual destructor.

116. In MFC, from which class do most classifications inherit?

  CObject

117. What is a balanced binary tree?

A: both the left and right subtrees are balanced binary trees, and the approximate logarithm of the depth difference between the left and right subtrees is not greater than 1

118. What’s wrong with the statement for (; 1;)? What does it mean?

A: infinite loop, the same as while (1).

119. There are three steps in the process of deriving a new class

1. Base class members

2. Transform the base class members

3. Add new members

121. TCP / IP connection process

In TCP / IP protocol, TCP protocol provides reliable connection service and establishes a connection by three handshakes.

First handshake: when establishing a connection, the client sends a connection request to the server and enters syn_ Send status, waiting for server confirmation;

The second handshake: the server receives the client connection request and sends the connection permission response to the client. At this time, the server enters syn_ Recv status;

The third Handshake: the client receives the server’s permission to connect and sends confirmation to the server. The client and the server enter the communication state and complete the three handshakes

122. The difference between memset and memcpy

Memset is used to set all a memory space to a certain character. It is generally used to initialize the defined string to ”.

Memcpy is used to copy memory. You can use it to copy objects of any data type, and you can specify the length of the copied data;

123. what is called the function compiled by the C compiler in the C++ program? Why do we need to add extern “C”? (*****************************************)

A: C + + language supports function overloading, while C language does not. The name of the function compiled by C + + in the library

Different from C language. Suppose that the prototype of a function is void foo (int x, int y); the name of the function in the library after compiled by C compiler is_ Foo, while the C + + compiler produces_ foo_ int_ Names like int. C + + provides C connection exchange to specify the symbol extern “C” to solve the name matching problem.

How to define a pure virtual function? What is the name of a class with pure virtual functions?

Add = 0 after the virtual function, and the class containing the virtual function is called abstract class.

 

current read

C + + language is in the_ C _ It’s developed on the basis of language.

126. The compiler unit of C + + language is the extension____ .cpp______ Of____ Procedures______ Documents.

127. At the end of the line, use the start marker of the comment as____ //_____。

128. The start and end markers of multiline comments are_____ /**/ _______。

129. The standard output stream object used to output expression values is____ cout_____。

130. The standard input stream object used to enter values for variables from the keyboard is__ cin______。

131. A complete program must have one named____ main____ Function of.

132. The body of a function is a function____ Compound_____ sentence.

133. When a CIN statement is executed, each data input from the keyboard must be followed by one___ Blank_____ Before entering the next data.

134. The precompiled command that contains a header file or program file in C + + program is____ #include ______。

135. The preprocessing command in the program refers to___ #___ A command that begins with a character.

136. An expression statement must be___ Semicolon___ As a terminator.

137. The header file contained in the # include command can be a system defined header file or a system defined header file___ User (or programmer)_____ Defined header file.

138. Use the # include command to include either a header file or a__ Procedures____ Documents.

139. A function is defined by__ Function header______ And__ Function body_____ It consists of two parts.

140. If the definition of a function precedes the function calling it, the definition of the function can be omitted at the beginning of the program__ Prototype (or declaration)____ sentence.

141. The extensions of C + + header file and source program file are__ .h ___ And___ .cpp ___。

142. The compilation errors of program files are divided into____ Warning____ And____ Fatal (error)____ There are two types.

143. When using___ void ____ When a word is reserved as a function type, the function does not return any value.

144. When the function parameter table is used___ void __ If the word representation is reserved, the parameter table is empty.

145. According to a function prototype statement “int fun1 (void);”, the return type of the function is__ int____ , which has___ 0___ Two parameters.

146. When the cout statement is executed to output the endl data item, the cursor on the C + + display output screen will be moved from the current position to the current position___ Next line_____ The starting position of.

147. Assuming x = 5 and y = 6, the value of the expression x + + * + + y is___ 35_______。

148. Assuming x = 5 and y = 6, the value of the expression X — * — y is___ 25_______。

149. Assuming x = 5 and y = 6, the values of X and y are___ 6___ And___ 30 _____。

150. Assuming that x = 5 and y = 6, the values of X and y are____ 4__ And___ 11___。

151. The decimal value of C + + constant 0x145 is___ 325 ___。

152. The decimal value of C + + constant 0345 is____ 229__。

153. The hexadecimal C + + corresponding to decimal constant 245 is____ 0xF5___。

154. C + + of octal corresponding to decimal constant 245 is___ 0365 ___。

155. The range of the signed char type is__ -128__ To___ +127 __ The integer between.

156. Int and float data occupy___ 4___ And____ 4___ It’s a byte.

157. Data of type float and double occupy____ 4___ And_____ 8___ It’s a byte.

158. Data of bool and char types are used respectively_____ 1____ And____ 1___ It’s a byte.

159. The lengths of the types of unsigned short int and int are____ 2___ And____ 4___。

160. The length of the string “this’s a book. N” is_____ 15____。

161. The length of the string “nThis’s a pennn” is_____ 15_____。

162. Storing string “ABCDEF” in C + + requires at least___ 7 _____ It’s a byte.

163. Storing string “a + B = C” in C + + requires at least_____ 6 ___ It’s a byte.

164. Assuming that X and y are integers and their values are 16 and 5 respectively, the values of X% Y and X / y are___ 1_______ And____ 3____。

165. Assuming that X and y are integers and their values are 16 and 5 respectively, the values of X / Y and double (x) / y are____ 3____ And___ 3.2____。

166. Suppose x is a logical quantity, then the value of X & & true is___ x ____。

167. Suppose x is a logical quantity, then the value of X || true is_____ True (or 1).

168. Suppose x is a logical quantity, then the value of X & & false is____ False (or 0).

169. Suppose x is a logical quantity, then the value of X | false is X.

170. Suppose x is a logical quantity, then the value of! X | false is____ !x ____。

171. Suppose x is a logical quantity, then the value of X is____ False (or 0).

172. Suppose x is a logical quantity, then the value of X |! X is____ True (or 1).

173. Let enum printstatus {ready, busy, error}; then cout<

174. Let enum printstatus {ready = 2, busy, error}; then cout<

175. The constants -4.205 and 6.7e-9 have___ 4_____ And____ 2___ This is a significant number.

176. Each enumeration value in an enumeration type is a____ Enumeration constants_____ One of its values___ Integer.

177. The data types of constants 100 and 3.62 are____ int ___ And_____ double ___。

178. If x = 5, y = 10, then after calculating the expression of Y * = + + X, the values of X and y are___ 6___ And__ 60 ___。

179. Assuming that X and CH are of int type and char type respectively, the values of sizeof (x) and sizeof (CH) are__ 4__ And__ 1__。

180. Assuming x = 10, the expression x < = 10? 20:30 is__ 20 __。

181. The values of sqrt (81) and pow (6,3) are___ 9 ___ And___ 216___。

182. The value of the expression rand() with random function___ 0__ To___ 19 __ Within the range.

183. In a switch statement, the expression after the keyword case in each statement label must be___ Constant.

184. In an IF statement, each else keyword is the same level and closest to its front____ if ____ Keyword matching.

185. The C + + reserved words case and defaule used as statement labels can only be used for___ switch ___ In the definition body of the statement.

186. When the switch statement is executed, after evaluating the expression as a condition, it will be executed downward from a matching label position. When it comes to the next label position (stop / don’t stop)___ Don’t stop__ Implementation.

187. If the “head” of the while loop is “while (I + + < = 10)” and the initial value of I is 0, and the value of I will not be modified in the loop body, the loop body will be executed repeatedly__ 11___ After three times, it ended normally.

188. If the “tail” of the do loop is “while (+ + I < 10)” and the initial value of I is 0, and the value of I will not be modified in the loop body, the loop body will be executed repeatedly___ 10 ___ After three times, it ended normally.

189. When the break statement is executed in the program, the execution of the loop class statement or switch statement of this layer will be ended.

190. When the___ continue___ Statement, an execution of the loop body in the loop statement is ended.

191. Execute to__ return ___ Statement will end the execution of the function and return to the location where the function was called.

192. At the end of the procedure____ Main (or main)__ After the function is called, the execution of the whole program will be finished and return to the C + + integrated development window.

193. The array a [10] of element type int occupies___ 40___ Bytes of storage space.

194. Two dimensional array a [4] [6] with element type of double____ 192__ Bytes of storage space.

195. Two dimensional array a [10] [30] with element type char occupies___ 300__ Bytes of storage space.

196. The storage character ‘a’ and string ‘a’ need to be occupied respectively_____ 1___ And____ 2 ___ It’s a byte.

197. The basic unit of an object-oriented system is_____ Object.

198. Each object is a member of its class__ Examples.

199. C + + supports two kinds of polymorphism___ Compile____ Polymorphism and genetic diversity of the gene____ Operation__ The results showed that there was no significant difference between the two groups.

200. In C + +, compile time polymorphism is achieved through___ Overload___ Implementation, while runtime polymorphism is achieved through___ Virtual function____ It’s possible. For any member defined in the class, the implied access is___ Private (or private).

201. For any member defined in the structure, the implied access rights are__ Public (or public).

202. If a complete definition of a member function is given in the definition body of a class, then the function belongs to__ Inline__ Function.

203. In order to avoid modifying any data member in the object when calling a member function, we should add a__ const __ keyword.

204. If you only need to read the value of a data member through a member function without modifying it, you should add a__ const __ keyword.

205. The differences between overloading, covering and hiding of class member functions:

Characteristics of overloaded member functions:

(1) The same scope (in the same class);

(2) The function name is the same;

(3) The parameters are different;

(4) The virtual keyword is optional.

Covering means that derived functions cover base functions

(1) Different scopes (in derived class and base class respectively);

(2) The function name is the same;

(3) The parameters are the same;

(4) The base class function must have the virtual keyword.

“Hidden” means that the function of derived class blocks the base class function with the same name. The rules are as follows:

(1) If the function of the derived class has the same name as the function of the base class, but the parameters are different. At this point, the functions of the base class will be hidden (don’t be confused with overloading) regardless of the virtual keyword.

(2) If the function of the derived class has the same name as the function of the base class, and the parameters are the same, but the base class function does not have the virtual keyword. At this point, the functions of the base class are hidden (be careful not to confuse them with overlays).

1. What is the idea of object-oriented programming?

A: the data structure and the method of operating the data structureencapsulationForm objects one by one.

2. What is class?

Answer: classify some common objects to form a collection, which is called class.

3. What are the two characteristics of objects? What do they mean?

A: the characteristics of the objects are as follows:static stateFeatures anddynamicfeatures.

Static characteristicsIt refers to some properties that can describe an object.

Dynamic characteristicsIt refers to the behavior of the object.

4. What is the significance of declaring a class in the header file and defining a class in the corresponding implementation file?

A: 1Improve compilation efficiencyBecause if the class is separated, it only needs to be compiled once. After generating the corresponding. Obj file, the class will not be compiled again where it is applied again, which greatly improves the efficiency.

        2.The code is hidden

5. Define the function body of the member function inside the class. What kind of attributes does this function have?

A: this function will automaticallyInline functionThis functionfunction callCode replacement will be carried out during the compilation phase.

6. What do member functions use to distinguish member data of different objects? Why can it be distinguished?

A: Yesthis pointer Because it points to the objectFirst address

7. What are the four default functions automatically generated by the C + + compiler for classes?

A:defaultConstructors (constructors without arguments),CopyConstructors (for assignments between objects),DeconstructionFunction,assignmentFunction (assignment of equal sign).

8. Under what circumstances will the copy constructor be called?

Answer: 1. When an object of a class is initializedThis categoryAnother object of.

2. If the formal parameter of a function is an object of a class, call the function to combine the formal parameter with the actual parameter.

3. If the return value of the function is a class object, when the function call completes the return.

9. What is the difference between constructor and ordinary function in form? (the function of the constructor, its declaration form to analyze)

A: a constructor is a special member function of a class. In general, it is used to initialize object member variables.

The name of the constructor must beSame as class name, which has no type and returns no value.

10. When do I have to override the copy constructor?

A: when the constructor involvesDynamic storage allocationWrite your own copy constructor and make a deep copy.

11. What is the calling order of constructors?

Answer: 1. Call the base class constructor first

2. Initialize data members in declaration order

3. finally, call your own constructor.

12. In which cases must the initialization member list be used?

A: 1. Class members are constant members.

Object is a member of the classNo,Parameterless constructor.

3. When a member of a class is a constant variable.

13. What is a constant object?

Answer: constant object refers to the object whose member value cannot be modified in any situation.

14. What is the meaning of static function?

A: 1Out of classIt can not be accessed, but can be accessed through the static member function of the class;

2. When a class’s constructor is private, it doesn’t instantiate itself like a normal class, so it can only call the constructor through a static member function.

15. Is there any way to access the non-public members of a class outside the class?

A: friend, inheritance, public member function.

16. What is abstract class?

A: it is not used to define objects, but as a basic typeInherited classes

17. What is the meaning of operator overloading?

A: in order to make the operation of data of user-defined data type consistent with the operation form of data of internal defined data type.

18. What are the five operators that are not allowed to be overloaded?

Answer: 1.. * (member pointer access operation symbol)

2.:: field operator

3. Sizeof length operation symbol

4.? : conditional operation symbol

5. (member accessor)

19. Three ways of operator overloading?

A: ordinary function, friend function, class member function.

20. Why can’t stream operators be overloaded by class member functions? How to solve this problem?

Answer: because the member function overload of the class must be the first operatorownThe overload of convection operation requires that the first parameter beStream object. It is usually solved by friends.

21. The difference and relation between assignment operator and copy constructor?

A: the same point: they all copy one object to another.

Difference: the copy constructor involves creating a new object.

22. In which case do you want to call the destructor of this class?

A: at the end of the object life cycle.

23. How to share data among objects?

Answer: it is implemented through the static member variable of the class. Static member variables occupy their own independent space and are not private to an object.

24. What are the characteristics of friendship?

A: unidirectional, non transitive and non inheritable.

25. What is the initialization order of object members?

A: its order is not affected by their order in the initialization table at all. It is only related to the member objects in the classOrder of declarationIt’s up to you.

26. What is the relationship between class and object?

A: classes are objectsabstractObject is of classexample

27. What are the access properties for members of a class?

A: public, protected, private.

28. What is the difference between const char * P and char * const p?

A: if const is on the left side of the asterisk, const is used to modify the variable that the pointer points to, that is, the pointer points to a constant;

If const is to the right of the asterisk, const modifies the pointer itself, that is, the pointer itself is a constant.

29. Is it true that a parent class writes a virtual function, and if the subclass covers its function without adding virtual, it can also achieve polymorphism?

A: the virtual modifier will be inherited implicitly.

Virtual can be added or not. The functions covered by subclasses can be polymorphic without adding virtual.

30. What does function overload mean? What is the difference between it and the concept of virtual function?

A: function overload is a function with the same name to complete different functions. The compiler system realizes static polymorphism through the number and type of function parameters in the compilation phase. But remember: you can’t overload a function just by having different return values.

Virtual function is to declare a function as a virtual function by using the keyword virtual in the base class, which means that the function may be defined in the future derived class or extended on the basis of the base class. The system can only dynamically determine which function to call in the run-time, so the implementation isDynamic polymorphism. It embodies a vertical concept, that is, between base class and derived class.

31. Can constructors and destructors be overloaded? Why?

A: constructors can be overloaded, destructors can’t be overloaded.

Because the constructor can have more than one and can take parameters, while the destructor can only have one and can’t take parameters.

32. How to define and implement a member function of a class as a callback function?

A: the so-called callback function isbeforehandRegister the function in the system to let the system know the existence of the function. Later, when an event occurs, call the function to respond to the event.

When defining a member function of a class, prefix the function nameCALLBACKThat is to say, it is defined as a callback function, and its implementation is no different from ordinary member functions

33. How is the virtual function realized?

A: in short, we use the virtual function table

34. Abstract classes do not produce instances, but they also need constructors. 

35. From a template class, you can derive a new template class or a non template class.

36. What code will be executed before the main function is executed?

answer:Global objectsIs executed before the main function.

37. When a Class A does not have any member variables or member functions, what is the value of sizeof (a). If it is not zero, please explain why the compiler does not make it zero. (Autodesk)

Answer: definitely not zero.

For example, if it is zero, declare an array of class a [10] objects, and the space occupied by each object is zero, then it is impossible to distinguish a [0] from a [1].

38. What’s the difference between delete and delete?

A: delete only calls the destructor once, while delete [] calls the destructor of each member.

39. Do you want to call the parent class’s destructor when the subclass is destructed?

A: Yes. The order of destructor calls is to destruct the derived class first and then the base class. That is to say, when the base class is destructed, all the information of the derived class has been destroyed

**************************************************************************

40. Advantages and disadvantages of inheritance:

advantage:

1. Class inheritance is statically defined at compile time and can be used directly,

2. Class inheritance can easily change the implementation of parent class.

Disadvantages:

1. Because inheritance is defined at compile time, it cannot be defined at compile timeruntimeChanging the implementation of inheritance from a parent class

2. The parent class usually defines at least part of the behavior of the subclass, and any change of the parent class may affect the behavior of the subclass

3. If the inherited implementation is not suitable for solving the new problem, the parent class must be overridden or replaced by another more suitable class. This dependency limits flexibility and ultimately reusability.

41. Explain the difference between heap and stack

1. Stack – automatically allocated and released by the compiler, storing function parameter values, local variable values, etc.

2. Heap: it is usually allocated and released by the programmer. If the programmer does not release it, it may be recycled by the OS at the end of the program.

42. When are the constructors and destructors of a class called? Do they need to be called manually?

A: constructors are automatically called when creating class objects, and destructors are automatically called by the system at the end of class objects’ lifetime.

43. When to precompile:

1. A large code body that is always used and not often changed.

2. The program consists of several modules, all of which use a set of standard include files and the same compilation options. In this case, all included files can be precompiled into a precompiled header.

44. The role of polymorphism?

There are two main problems

1. Hide the implementation details to make the code modularized; extend the code module to achieve code reuse; 2;

2. Interface reuse: to ensure the correct call when using a property of any class instance in the family when the class inherits and derives

45. What’s the difference between virtual function and ordinary member function? Can inline functions and constructors be virtual functions?

A: 1. Virtual function has virtual keyword, virtual pointer and virtual function table. Virtual pointer is the interface of virtual function, but ordinary member function does not.

2. Inline functions and constructors cannot be virtual functions.

46. The calling order of constructors and destructors? Why should destructors be virtual?

The calling order of constructors: base class constructors – object member constructors – derived class constructors; the calling order of destructors is opposite to constructors.

2. Destructor virtualization is to prevent memory leakage caused by incomplete destructor.

47. Which functions can access member variables of type private in C + +?

It can only be accessed by member functions and friend functions in this class

48. Please tell us the differences among the three types of access restrictions: private, protected and public

1. Private is a private type, which can only be accessed by member functions in this class.

2. Protect is protected, which can be accessed by this class and inheritance class.

3. Public is a public type, which can be accessed by any class.

49. How to initialize member variables in a class?

It can be implemented through the initialization list of the constructor or the function body of the constructor.

50. When do I need to use “frequently quoted”?

If we want to use reference to improve the efficiency of the program and protect the data passed to the function from being changed in the function, we should use frequent reference.

51. What’s the difference between a reference and a pointer?

A: 1. The reference must be initialized, and the pointer does not have to be initialized.

2. The reference cannot be changed after initialization. The pointer can change the object it refers to.

3. There is no reference to null value, but there is a pointer to null value.

52. Describe the basic characteristics of real-time system

In a specific time to complete a specific task, real-time and reliability.

54. Are there any differences between global variables and local variables in memory? If so, what is the difference?

A. global variables are stored in the static data area, and local variables are stored in the stack.

55. What causes stack overflow?

A. there is no recycling resource

56. What functions cannot be declared virtual?

A: constructor

57. What are the two parts of IP address coding?

Answer IP address consists of two parts, network number and host number.

58. The parameter types that cannot switch() are:

A. the switch parameter cannot be real.

59. How to reference a defined global variable?

A. you can refer to the header file or use the extern keyword.

If you refer to a global variable declared in the header file by referring to the header file, if you write that variable wrong, an error will be reported during compilation. If you refer to it by using extern, if you make the same error, an error will not be reported during compilation, but during connection.

60. For a frequently used short function, what implementation should be applied in C language and C + +?

A. C is defined by macro and C + + by inline.

61. Is C + + type safe?

Answer: No. Two pointers of different types can be cast (using reinterpret cast)

63. Briefly describe the difference between array and pointer?

1. Arrays are created either in static storage (such as global arrays) or on the stack.

2. The pointer can point to any type of memory block at any time.

(1) Differences in content

char a[] = “hello”;

a[0] = ‘X’;

Char * P = “world”; / / note that P points to a constant string

P [0] =’x ‘; / / the compiler can’t find the error, run time error (* *

(2) The sizeof operator can be used to calculate the capacity (number of bytes) of an array. Sizeof (P), where p is the number of bytes of a pointer variable, not the memory capacity referred to by P.

The transfer method of value in 64. C + + function

There are three ways: value passing, pointer passing and reference passing.

65. Memory allocation

There are three ways of distribution

1. Static storage area, which has been allocated at the time of program compilation, exists during the whole running period, such as global variables and constants.

2. The local variables in the function are allocated from the stack, but the allocated memory is easy to be limited.

3. Heap allocation is also called dynamic allocation. For example, we use new and malloc to allocate memory and delete and free to free memory.

66. What is the function of extern “C”?

Extern “C” is a connection exchange symbol provided by C + +, which is used to tell C + + that this code is a C function.

This is because after C + + is compiled, the function name in the library will become very long, which is inconsistent with that generated by C. as a result, C + + can not directly call C functions. With the addition of extend “C”, C + + can directly call C functions.

Extern “C” mainly uses the reference and export of regular DLL functions and is used when C + + contains C functions or C header files. When using, you can add the keyword “external” C “in front of it.

67. What functions are used to open new processes and threads.

A: 1. Thread: create thread / afxbeginthread, etc.

2. Process: create process, etc.

68. What is the difference between SendMessage and PostMessage?

Answer: 1. SendMessage is blocked. After the message is processed, the code can go to the next line of SendMessage.

2. PostMessage is non blocking, no matter whether the message has been processed or not, the code will immediately go to the next line of PostMessage.

69. What are the main functions of cmemorystate?

A: check the memory usage and solve the problem of memory leakage.

What is the difference between “70.26”, “include” and “file name. H”?

Answer: 1. For # include, the compiler searches for file name. H from the standard library path

2. For # include “file name. H”, the compiler searches for file name. H from the user’s working path

71. What is the purpose of processor identification error?

A: an error message will be output at compile time, and the compilation will be stopped.

72.#if!defined(AFX_…_HADE_H)

#define(AFX_…_HADE_H)

……

#What is the role of ENDIF?

Prevent the header file from being repeatedly referenced.

73. What should we pay attention to when defining a macro?

Answer: each parameter in the definition section and the entire expression must bebracketsTo avoid unforeseen errors.

74. What type does an array change when it is used as a function argument?

A: arrays become pointer types when they are used as arguments.

75. What are the three standard files that the system will automatically open and close?

(1) Standard input keyboard stdin

(2) Standard output — display — stdout

(3) Standard error output — display — stderr

How many bits are char, int, float and double in Win32?

(1) Char takes 8 bits (1 byte)

(2) Int occupies 32 bits (4 bytes)

(3) Float occupies 32 bits (4 bytes)

(4) Double takes 64 bits (8 bytes)

77. What is the difference between strcpy() and memcpy()?

A: both strcpy() and memcpy() can be used to copy strings. The copy of strcpy() ends with ”, but memcpy() must specify the length of the copy.

78. Explain the difference between define and const in grammar and meaning?

(1) #define is a method of defining symbolic variables in C syntax. Symbolic constants are only used to express a value. In the compilation stage, symbols are replaced by values. It has no type;

(2) Const is a method to define constant variable in C + + syntax. Constant variable has variable property, it has type, there is a storage unit named after it in memory, and the length can be measured by sizeof.

79. Tell the difference between character constant and string constant, and use the operator sizeof to calculate?

A: the character constant refers to a single character, the string constant ends with ”, and the operator sizeof is used to calculate the storage space of more than one byte.

80. What are the advantages and disadvantages of global variables?

A: global variable is also called external variable. It is a variable defined outside the function. It belongs to a source program file. It saves the last modified value, which is convenient for data sharing, but inconvenient for management, and easy to cause unexpected errors.

81. Summarize the application and function of static? (**************************)

(1) The scope of the static variable in the function body is the function body, which is different from the auto variable. The memory of the variable is allocated only once, so its value will remain the last value in the next call;

void fun1()

{

static int a = 0;

int b = 0;

int sum_a= 0;

sum_a = sum_a + a++;

int sum_b = 0;

sum_b =sum_b + b++;

cout << sum_a << “” << sum_b << endl;

}

int main(int argc, char* argv[])

{

int i = 0;

while( i < 10 )

{

fun1();

i++;

}

return 0;

}/ / in this example, sum_ A is always accumulating. And sum_ B has always been zero

(2) The static global variables in the module can be accessed by the functions used in the module, but not by other functions outside the module;

(3) the first mock exam static function in the module can be called by other functions in this module, which is restricted to the module of its declaration.

(4) The static member variable in the class belongs to the whole class, and there is only one copy of all objects in the class;

(5) The static member function in the class belongs to the whole class. This function does not receive this pointer, so it can only access the static member variable of the class.

82. Summarize the application and function of const? (**************************)

(1) To prevent a variable from being changed, use the const keyword. When defining the const variable, you usually need to initialize it, because there is no chance to change it later;

(2) For a pointer, you can specify that the pointer itself is const, the data the pointer refers to is const, or both are const;

(3) In a function declaration, const can modify a formal parameter to indicate that it is an input parameter and its value cannot be changed inside the function;

(4) For a member function of a class, if it is of const type, it means that it is a constant function and cannot modify the member variables of the class_ name() const {}

(5) For a member function of a class, it is sometimes necessary to specify its return value as const type, so that its return value is not “lvalue”. const void fun_ name() {}

83. What is a pointer? What’s your understanding of pointer?

A: 1. Pointer is a variable, which is used to store memory address.

2. The type of pointer variable depends on the data type it points to. Add the*

3. The characteristic of pointer variable is that it can access the memory it points to.

84. What is a constant pointer and what is a pointer to a constant variable?

Answer: 1. The meaning of constant pointer is that the address pointed to by the pointer cannot be changed, but the content pointed to by the address can be changed. Using constant pointer can ensure that our pointer cannot point to other variables.

2. A pointer to a constant variable means that the address of the variable itself of the pointer can be changed and it can point to other variables, but the content it refers to cannot be modified.

85. The difference between function pointer and pointer function?

A: 1. A function pointer is a pointer to a function entry.

2. Pointer function means that the return value of function is a pointer type.

87. What’s the difference between debug and release?

The debug version is the debug version, and the release version is the final non debug version released to users.

88. Several typical applications of pointer?

Int * P [n]; — pointer array, each element is a pointer to integer data.

Int (*) P [n]; — P is a pointer to one-dimensional array, which has n integer data.

Int (* P) [n]; correct definition of array pointer.

//There’s a mistake here!!! int (*p)[n]????????

Int * p(); — function returns a pointer to the returned value.

Int (*) P (); — – P is a pointer to a function.

//Here’s the row and column pointer.

int main(int argc, char* argv[])

{

int c[2][4];

c[0][0] = 1;

c[0][1] = 2;

c[0][2] = 3;

c[0][3] = 4;

c[1][0] = 5;

c[1][1] = 6;

c[1][2] = 7;

c[1][3] = 8;

Int (* P) [4] = C + 0; / / C + 0 is the row pointer! Define a row pointer int (* P) [n],

//Int * P1 = C + 1; / / an error will be reported here. : cannot convert from ‘int (*)[4]’ to ‘int *’

Int * PA = * C + 1; / / * C + 1 represents the column pointer.!

return 0;

}

//On the concept of function pointer.

void myfun( int a, int b)

{

int c = 0;

int d = 0;

cout << “sdfsd” << endl;

}

void myfun1( int a, int b)

{

int c = 0;

int d = 0;

cout << “sdfsd” << endl;

}

typedef void (*PMYFUN)( int a, int b );

Pmyfun ifxn; / / define a variable with this new type!

int main(int argc, char* argv[])

{

Ifxn = myfun; / / assign a value to the pointer variable to indicate which function it points to.

iFxn(2, 3);

iFxn = myfun1;

Ifxn (32, 3); / / y remove the specific function with pointer.

return 0;

}

//On the concept of function pointer.

On the concept of function pointer. This pthreadproc can be understood as a new type, except that it is a pointer.

Pthreadproc pfun1; / / the variable defined with pthreadproc is a pointer.

Pfun1 = myfun; / / this is the core code, which will indicate which function is called.

current read

89. What is the difference between static function and ordinary function?

Static functions have only one copy in memory, while ordinary functions maintain one copy in each called function

90. What’s the difference between structure and union?

A: 1. Structure and union are composed of multiple members of different data types, but at any one time, only one selected member is stored in the Union (all members share a common address space), while all members of the structure exist (different members have different storage addresses).

2. For different members of the union, the values of other members will be rewritten, and the values of the original members will not exist, but for different members of the structure, the values will not affect each other.

91. What’s the difference between class and struct?

A: struct members are public by default, while class members are private by default.

92. Brief description of enumeration types?

A: it’s convenient to define a group of constants at a time, which is very convenient to use;

93. The function of assert()?

Answer: assert () is a macro that is often used when debugging programs. When the program is running, it calculates the expression in brackets. If the expression is false (0), the program will report an error and terminate execution. If the expression is not 0, the following statements continue. This macro is usually used to determine whether there is obviously illegal data in the program. If there is termination of the program, it will not lead to serious consequences, but also easy to find errors.

94. Can local variables and global variables have the same name?

A: Yes, the part will shield the whole. To use global variables, you need to use ‘:’ (field operator).

95. The local variables of the program exist in (stack), the global variables exist in (static area), and the dynamic application data exist in (heap).

96. When to use it?

A: if you want to use reference to improve the efficiency of the program and protect the data passed to the function from being changed in the function, you should use frequent reference.

97. What are the benefits of separating class declaration from implementation?

1. It has a protective effect;

2. Improve the efficiency of compilation.

What are the components of 98. Windows message system?

It consists of the following three parts:

1. Message queue: the operating system is responsible for maintaining a message queue for the process, and the program continuously obtains and processes messages from the message queue.

2. Message loop: the application continuously obtains and processes messages through message loop.

3. Message processing: the message loop is responsible for sending messages to related windows and using the associated window procedure function for processing.

99. What is message mapping?

Message mapping is to let the programmer specify MFC class (a class with message processing ability) to process a message. Then the programmer completes the writing of the processing function to realize the message processing function.

100. What is UDP and what is the difference between TCP?

The full name of TCP is transmission control protocol. This protocol can provide connection oriented, reliable, point-to-point communication.

UDP is fully known as user message protocol, which can provide non connection and unreliable point to multipoint communication.

With TCP or UDP, it depends on which aspect your program focuses on? Reliable or fast?

101. The main implementation steps of Winsock connection?

Answer: 1. Server side: socket() establishes a socket, binds and listens, and uses accept() to wait for the client to connect. When accept() finds that there is a client connection, it establishes a new socket and starts waiting for the connection again. The newly generated socket uses send() and recv() to write and read data until the data exchange is completed, and closesocket() closes the socket.

2. Client: socket() establishes a socket, connects to the server, and then uses send() and recv() to write and read data on the socket until the data exchange is completed, and closesocket() closes the socket.

102. What are the main communication methods between processes?

A: semaphores, pipes, messages, shared memory

103. What are the three dynamic link libraries that make up the functions of the Win32 API?

A: kernel library, user interface management library, graphical device interface library.

104. What are the steps to create a window?

A: fill in a window class structure, register the window class, create a window, display a window, and update a window.

105. What is the difference between modal and non modal dialog boxes?

A: 1. Different calling rules: the former is called with domodal(), while the latter is displayed by attributes and showwindow().

2. Before the modal dialog box is closed, the user can’t do other operations, but the non modal dialog box can.

3. When creating a non modal dialog box, you must write your own common constructor and call the create() function.

106. Take the data from the edit box to the associated variable. What is the function that has displayed the data of the associated variable on the edit box?

Answer: take out the update data (true) and display the update data (false)

107. A brief introduction to GDI?

GDI is the abbreviation of graphics device interface, translated as: graphics device interface; it is a function library which is implemented in Windows application program and has nothing to do with the device. These functions produce graphics and text output on different output devices.

108. What are the types of windows messages? And make a simple description of all kinds.

1. Window messages: messages related to windows, except WM_ All commands except command are WM_ The beginning of the message;

For user requests, 2_ The message indicated by command;

3. Control notification message: unified by WM_ Notift said,

4. User defined message.

109. How to customize messages?

Using WM_ User and WM_ App uses two macros to customize messages,

110. Describe the relationship between visual c + +, Win32 API and MFC?

(1) Visual C + is an integrated and visual programming environment based on C + + programming language;

(2) Win32 API is a set of application program interfaces provided by 32-bit windows operating system in the form of C / C +;

(3) MFC encapsulates the Win32 API, which simplifies the development process.

111. How to eliminate ambiguity in multiple inheritance?

1. Member qualifier

2. Virtual base class

What is static correlation and what is dynamic correlation

In polymorphism, if the program can determine the actual execution action in the compilation phase, it is called static Association,

If you wait for the program to run, it is called dynamic association.

Two necessary conditions for 113 polymorphism

1. A pointer or reference to a base class points to a derived class object,

2. Virtual function

114. What is a smart pointer?(*****************************************)

A: when there is a pointer to another class object in a class, overload the pointer operator, then the current class object can call the member of another class as its own member.

115. When do I need to use virtual destructors?

A: when the base class pointer points to the derived class object generated by the new operator, when the base class pointer is deleted, the derived class part is not released, resulting in incomplete release, which requires a virtual destructor.

116. In MFC, from which class do most classifications inherit?

CObject

117. What is a balanced binary tree?

A: both the left and right subtrees are balanced binary trees, and the approximate logarithm of the depth difference between the left and right subtrees is not greater than 1

118. What’s wrong with the statement for (; 1;)? What does it mean?

A: infinite loop, the same as while (1).

119. There are three steps in the process of deriving a new class

1. Base class members

2. Transform the base class members

3. Add new members

121. TCP / IP connection process

In TCP / IP protocol, TCP protocol provides reliable connection service and establishes a connection by three handshakes.

First handshake: when establishing a connection, the client sends a connection request to the server and enters syn_ Send status, waiting for server confirmation;

The second handshake: the server receives the client connection request and sends the connection permission response to the client. At this time, the server enters syn_ Recv status;

The third Handshake: the client receives the server’s permission to connect and sends confirmation to the server. The client and the server enter the communication state and complete the three handshakes

122. The difference between memset and memcpy

Memset is used to set all a memory space to a certain character. It is generally used to initialize the defined string to ”.

Memcpy is used to copy memory. You can use it to copy objects of any data type, and you can specify the length of the copied data;

123. what is called the function compiled by the C compiler in the C++ program? Why do we need to add extern “C”? (*****************************************)

A: C + + language supports function overloading, while C language does not. The name of the function compiled by C + + in the library

Different from C language. Suppose that the prototype of a function is void foo (int x, int y); the name of the function in the library after compiled by C compiler is_ Foo, while the C + + compiler produces_ foo_ int_ Names like int. C + + provides C connection exchange to specify the symbol extern “C” to solve the name matching problem.

How to define a pure virtual function? What is the name of a class with pure virtual functions?

Add = 0 after the virtual function, and the class containing the virtual function is called abstract class.

 

current read

C + + language is in the___ C ______ It’s developed on the basis of language.

126. The compiler unit of C + + language is the extension____ .cpp______ Of____ Procedures______ Documents.

127. At the end of the line, use the start marker of the comment as____ //_____。

128. The start and end markers of multiline comments are_____ /**/ _______。

129. The standard output stream object used to output expression values is____ cout_____。

130. The standard input stream object used to enter values for variables from the keyboard is__ cin______。

131. A complete program must have one named____ main____ Function of.

132. The body of a function is a function____ Compound_____ sentence.

133. When a CIN statement is executed, each data input from the keyboard must be followed by one___ Blank_____ Before entering the next data.

134. The precompiled command that contains a header file or program file in C + + program is____ #include ______。

135. The preprocessing command in the program refers to___ #___ A command that begins with a character.

136. An expression statement must be___ Semicolon___ As a terminator.

137. The header file contained in the # include command can be a system defined header file or a system defined header file___ User (or programmer)_____ Defined header file.

138. Use the # include command to include either a header file or a__ Procedures____ Documents.

139. A function is defined by__ Function header______ And__ Function body_____ It consists of two parts.

140. If the definition of a function precedes the function calling it, the definition of the function can be omitted at the beginning of the program__ Prototype (or declaration)____ sentence.

141. The extensions of C + + header file and source program file are__ .h ___ And___ .cpp ___。

142. The compilation errors of program files are divided into____ Warning____ And____ Fatal (error)____ There are two types.

143. When using___ void ____ When a word is reserved as a function type, the function does not return any value.

144. When the function parameter table is used___ void __ If the word representation is reserved, the parameter table is empty.

145. According to a function prototype statement “int fun1 (void);”, the return type of the function is__ int____ , which has___ 0___ Two parameters.

146. When the cout statement is executed to output the endl data item, the cursor on the C + + display output screen will be moved from the current position to the current position___ Next line_____ The starting position of.

147. Assuming x = 5 and y = 6, the value of the expression x + + * + + y is___ 35_______。

148. Assuming x = 5 and y = 6, the value of the expression X — * — y is___ 25_______。

149. Assuming x = 5 and y = 6, the values of X and y are___ 6___ And___ 30 _____。

150. Assuming that x = 5 and y = 6, the values of X and y are____ 4__ And___ 11___。

151. The decimal value of C + + constant 0x145 is___ 325 ___。

152. The decimal value of C + + constant 0345 is____ 229__。

153. The hexadecimal C + + corresponding to decimal constant 245 is____ 0xF5___。

154. C + + of octal corresponding to decimal constant 245 is___ 0365 ___。

155. The range of the signed char type is__ -128__ To___ +127 __ The integer between.

156. Int and float data occupy___ 4___ And____ 4___ It’s a byte.

157. Data of type float and double occupy____ 4___ And_____ 8___ It’s a byte.

158. Data of bool and char types are used respectively_____ 1____ And____ 1___ It’s a byte.

159. The lengths of the types of unsigned short int and int are____ 2___ And____ 4___。

160. The length of the string “this’s a book. N” is_____ 15____。

161. The length of the string “nThis’s a pennn” is_____ 15_____。

162. Storing string “ABCDEF” in C + + requires at least___ 7 _____ It’s a byte.

163. Storing string “a + B = C” in C + + requires at least_____ 6 ___ It’s a byte.

164. Assuming that X and y are integers and their values are 16 and 5 respectively, the values of X% Y and X / y are___ 1_______ And____ 3____。

165. Assuming that X and y are integers and their values are 16 and 5 respectively, the values of X / Y and double (x) / y are____ 3____ And___ 3.2____。

166. Suppose x is a logical quantity, then the value of X & & true is___ x ____。

167. Suppose x is a logical quantity, then the value of X || true is_____ True (or 1).

168. Suppose x is a logical quantity, then the value of X & & false is____ False (or 0).

169. Suppose x is a logical quantity, then the value of X | false is X.

170. Suppose x is a logical quantity, then the value of! X | false is____ !x ____。

171. Suppose x is a logical quantity, then the value of X is____ False (or 0).

172. Suppose x is a logical quantity, then the value of X |! X is____ True (or 1).

173. Let enum printstatus {ready, busy, error}; then cout<

174. Let enum printstatus {ready = 2, busy, error}; then cout<

175. The constants -4.205 and 6.7e-9 have___ 4_____ And____ 2___ This is a significant number.

176. Each enumeration value in an enumeration type is a____ Enumeration constants_____ One of its values___ Integer.

177. The data types of constants 100 and 3.62 are____ int ___ And_____ double ___。

178. If x = 5, y = 10, then after calculating the expression of Y * = + + X, the values of X and y are___ 6___ And__ 60 ___。

179. Assuming that X and CH are of int type and char type respectively, the values of sizeof (x) and sizeof (CH) are__ 4__ And__ 1__。

180. Assuming x = 10, the expression x < = 10? 20:30 is__ 20 __。

181. The values of sqrt (81) and pow (6,3) are___ 9 ___ And___ 216___。

182. The value of the expression rand() with random function___ 0__ To___ 19 __ Within the range.

183. In a switch statement, the expression after the keyword case in each statement label must be___ Constant.

184. In an IF statement, each else keyword is the same level and closest to its front____ if ____ Keyword matching.

185. The C + + reserved words case and defaule used as statement labels can only be used for___ switch ___ In the definition body of the statement.

186. When the switch statement is executed, after evaluating the expression as a condition, it will be executed downward from a matching label position. When it comes to the next label position (stop / don’t stop)___ Don’t stop__ Implementation.

187. If the “head” of the while loop is “while (I + + < = 10)” and the initial value of I is 0, and the value of I will not be modified in the loop body, the loop body will be executed repeatedly__ 11___ After three times, it ended normally.

188. If the “tail” of the do loop is “while (+ + I < 10)” and the initial value of I is 0, and the value of I will not be modified in the loop body, the loop body will be executed repeatedly___ 10 ___ After three times, it ended normally.

189. When the break statement is executed in the program, the execution of the loop class statement or switch statement of this layer will be ended.

190. When the___ continue___ Statement, an execution of the loop body in the loop statement is ended.

191. Execute to__ return ___ Statement will end the execution of the function and return to the location where the function was called.

192. At the end of the procedure____ Main (or main)__ After the function is called, the execution of the whole program will be finished and return to the C + + integrated development window.

193. The array a [10] of element type int occupies___ 40___ Bytes of storage space.

194. Two dimensional array a [4] [6] with element type of double____ 192__ Bytes of storage space.

195. Two dimensional array a [10] [30] with element type char occupies___ 300__ Bytes of storage space.

196. The storage character ‘a’ and string ‘a’ need to be occupied respectively_____ 1___ And____ 2 ___ It’s a byte.

197. The basic unit of an object-oriented system is_____ Object.

198. Each object is a member of its class__ Examples.

199. C + + supports two kinds of polymorphism___ Compile____ Polymorphism and genetic diversity of the gene____ Operation__ The results showed that there was no significant difference between the two groups.

200. In C + +, compile time polymorphism is achieved through___ Overload___ Implementation, while runtime polymorphism is achieved through___ Virtual function____ It’s possible. For any member defined in the class, the implied access is___ Private (or private).

201. For any member defined in the structure, the implied access rights are__ Public (or public).

202. If a complete definition of a member function is given in the definition body of a class, then the function belongs to__ Inline__ Function.

203. In order to avoid modifying any data member in the object when calling a member function, we should add a__ const __ keyword.

204. If you only need to read the value of a data member through a member function without modifying it, you should add a__ const __ keyword.

205. The differences between overloading, covering and hiding of class member functions:

Characteristics of overloaded member functions:

(1) The same scope (in the same class);

(2) The function name is the same;

(3) The parameters are different;

(4) The virtual keyword is optional.

Covering means that derived functions cover base functions

(1) Different scopes (in derived class and base class respectively);

(2) The function name is the same;

(3) The parameters are the same;

(4) The base class function must have the virtual keyword.

“Hidden” means that the function of derived class blocks the base class function with the same name. The rules are as follows:

(1) If the function of the derived class has the same name as the function of the base class, but the parameters are different. At this point, the functions of the base class will be hidden (don’t be confused with overloading) regardless of the virtual keyword.

(2) If the function of the derived class has the same name as the function of the base class, and the parameters are the same, but the base class function does not have the virtual keyword. At this point, the functions of the base class are hidden (don’t be confused with covering)

Author: young commander Yangjie
Link: https://www.jianshu.com/p/01721f639924
Source: Jianshu
The copyright belongs to the author. For commercial reprint, please contact the author for authorization. For non-commercial reprint, please indicate the source.

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]