C + + Face Test continued

Source: Internet
Author: User
Tags assert message queue variable scope

51. What is the difference between a reference and a pointer?

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

2) The reference initialization cannot be changed and the pointer can change the object being referred to.

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



52. Describe the basic features of a real-time system

A specific task, real-time and reliability, in a given period of time.



54. Are global variables and local variables different in memory? If so, what's the difference?

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



55. What is the cause of the stack overflow?

Answer, no recycling of waste resources



56. What functions cannot be declared as virtual functions?

Answer Constructor (constructor)



What are the two parts of IP address encoding?

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



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

The parameter of switch cannot be a real type.



59. How do I refer to a global variable that has already been defined?

A, you can use the method of referring to the header file, you can also use the extern keyword, if you use a reference header file to refer to a global variable declared in the header file, assuming that you write the error, then the compilation will be error, if you use the extern way to reference, assuming you made the same mistake, Then no error during compilation, and error during connection



60. For a short function that is frequently used, what implementations are applied in C and what implementations are applied in C + +?

A, c with a macro definition, C + + with inline

is C + + type-safe?

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



62. When a class A does not have any member variables and member functions, then what is the value of sizeof (a), please explain why the compiler did not let it be zero.

Answer: for 1. For example, if it is 0, declare a class A[10] object array, and each object occupies a zero space, then there is no way to differentiate a[0],a[1] ... The



63. Describe the difference between an array and a pointer?

A: The array is either created in a static store (such as a global array), or it is created on the stack. Pointers can point to any type of memory block at any time.

(1) Differences in the content of the changes

Char a[] = "Hello";

A[0] = ' X ';

Char *p = "World"; Note P points to the constant string

P[0] = ' X '; The compiler cannot find the error, run-time error

(2) Use the operator sizeof to calculate the capacity (in bytes) of the array. sizeof (p), p is the pointer to the number of bytes of a pointer variable, not the memory capacity referred to by P.



. How values are passed in C + + functions

Answer: There are three ways: value passing, pointer passing, reference passing



65. How to allocate memory

A: There are three ways to allocate

1, static storage, is at the time of the program compile has been allocated well, during the entire run, such as global variables, constants.

2, the allocation of the stack, the local variables within the function is allocated from this, but the allocation of memory is easy to be limited.

3, heap allocation, also known as dynamic allocation, such as we use New,malloc to allocate memory, with Delete,free to release memory.



What is the role of extern "C"?

A: Extern "C" is a connection Exchange specified symbol provided by C + + that tells C + + that this code is a C function. This is because C + + compiled library function name will become very long, inconsistent with C generation, resulting in C + + cannot directly call C function, plus extren "C", C + + can directly invoke C function.

Extern "C" is used primarily for referencing and exporting of regular DLL functions and for C + + or C-header files in C + +. Use the extern "C" keyword in front of you. The real purpose of the extern "C" statement can be summed up in one sentence: the implementation of mixed programming between C + + and C and other languages.





67. What function to use to open a new process, thread.

Answer:

Threads: Createthread/afxbeginthread, etc.

Process: CreateProcess, etc.



What's the difference between SendMessage and postmessage?

Answer: SendMessage is blocked, and when the message is processed, the code can go to the next line of SendMessage. PostMessage is non-blocking, and the code immediately goes to the next line of PostMessage regardless of whether the message has been processed.



What is the main function of CMemoryState?

Answer: Review memory usage to resolve memory leak issues.



What is the difference between #include and #include "filename.h"?

A: For # include, the compiler starts searching the standard library path filename.h

For # include "Filename.h", the compiler starts searching from the user's work path filename.h



71. What is the purpose of the processor identification #error?

A: Compile-time output an error message, and abort continue compiling.



#if!defined (Afx_..._hade_h)

#define (Afx_..._hade_h)

......

#endif作用?

A: Prevent the header file from being repeatedly referenced.



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

A: Each parameter of the definition section and the entire expression must be enclosed in parentheses to avoid unexpected errors



74. When a function argument is made by an array, what type does it change?

A: An array becomes a pointer type when it makes an argument.



75. What are the 3 standard files that the system automatically turns on and off?

(1) standard input--keyboard-stdin

(2) Standard output--display-stdout

(3) standard error output--Display-stderr



76.: Under Win32 char, int, float, double how many bits each occupy?

(1) Char occupies 8 bits

(2) Int occupies 32 bits

(3) Float occupies 32 bits

(4) Double occupies 64 bits



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

A: both strcpy () and memcpy () can be used to copy a string, and the strcpy () copy ends with '% ', but memcpy () must specify the length of the copy.



78. How do define and const differ in syntax and meaning?

A: (1) #define是C语法中定义符号变量的方法, the symbolic constant is only used to express a value, in the compilation stage the symbol is replaced by the value, it has no type;

(2) const is a method of defining a constant variable in C + + syntax, which has a variable attribute, has a type, has a storage unit named in memory, and can measure the length with sizeof.



79. Tell the difference between a character constant and a string constant, and use the operator sizeof to calculate what is not used?

A: The character constant is a single character, the string constant ends with '/', and the operator sizeof calculates the storage space that takes up more than one byte.



80. Describe the pros and cons of global variables?

A: The global variable is also called an external variable, it is defined outside the function of the variable, it belongs to a source program file, it saves the last modified value, easy to share data, but inconvenient management, easy to cause unexpected errors.



81. Summarize the application and role of static?

A: (1) The function body static variable scope is the function body, different from the auto variable, the memory of the variable is allocated only once, so its value at the next call will still maintain the last value;

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

(3) The static function within the module can only be called by other functions within the module, and the use of the function is limited to the module in which it is declared;

(4) A static member variable in a class is owned by the entire class and has only one copy of all objects of the class;

(5) The static member function in a class is owned by the entire class, which does not receive the this pointer, and therefore can only access static member variables of the class.



82. Summarize the application and role of const?

Answer: (1) to prevent a variable from being changed, you can use the Const keyword. When defining the const variable, it is often necessary to initialize it, since there is no chance to change it again;

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

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

(4) For a class member function, if it is specified as a const type, it indicates that it is a constant function and cannot modify the member variables of the class;

(5) For a member function of a class, sometimes it is necessary to specify that its return value is a const type so that its return value is not "left value".



83. What is a pointer? Talk about your understanding of pointers?

A: The pointer is a variable that specifically stores the memory address;

The type of the pointer variable depends on the type of data it points to, plus * before the data type indicated

A pointer variable is characterized by its ability to access the memory it points to.



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

A: The constant pointer means that the address pointed to by the pointer does not change, but the address points to the content can be changed, using the constant pointer to ensure that our pointer can not point to other variables,

A pointer to a constant variable means that the address of the pointer's variable itself can vary, pointing to other variables, but what it refers to cannot be modified. Pointer to a long variable defined,



85. What is the difference between a function pointer and a pointer function?

Answer: The function pointer is a pointer to a function entry;

A pointer function is a pointer type that is the return value of a function.



87. Describe the difference between the debug version and release version?

A: The debug version is a debug version, release version is the final non-debug version released to the user,



88. What are some typical applications of pointers?

For:

An int *p[n];-– pointer array, each of which is a pointer to the integer data.

the Int (*) p[n];-p is a pointer to a one-dimensional array that has n integer data.

int *p ();--the function takes the pointer back, and the pointer points to the returned value.

Int (*) p ();--p is a pointer to a function.



What is the difference between a static function and a normal function?

A: The static function has only one copy in memory, and the normal function maintains one copy of each call.



What is the difference between a struct (struct) and a union (union)?

Answer: 1. Structs and unions are made up of a number of different data type members, but at any one time, the union only holds a selected member (all members share a single address space), and all members of the struct exist (different member's storage address).

2. For the different member assignments of the Union, the other members will be rewritten, the original member values will not exist, and for the different members of the structure of the assignment is not affected.



What is the difference between class and struct?

A: Members of a struct are public by default, and members of a class are private by default.



92. Describe the enumeration type?

A: Enumeration makes it easy to define a set of constants at a time;



What is the role of the. assert ()?

A: ASSERT () is a macro that is frequently used by a debugger when it evaluates an expression in parentheses when it runs, and if the expression is False (0), the program reports an error and terminates execution. If the expression is not 0, the following statement continues. This macro usually turns out that there is clearly illegal data in the program, and if a termination procedure is used to avoid serious consequences, it is also easy to find errors.



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

Answer: Yes. Local will mask the global. To use global variables, you need to use "::" (domain operator).



95. The local variables of the program exist in (the stack), the global variables exist in the (static zone), the dynamic request data exists in (heap).



96. When do I use a regular reference?

A: If you need to use reference to improve the efficiency of the program, but also to protect the data passed to the function is not changed in the function, you should use a constant reference.



97. What are the separate benefits of class declarations and implementations?

Answer: 1. Protective effect;

2. Improve the efficiency of compilation.



98. What are the components of the Windows Messaging system?

A: It consists of 3 parts:

1. Message Queuing: The operating system is responsible for maintaining a message queue for the process, the program runs continuously from the message queue to obtain messages, processing messages;

2. Message loop: The application is constantly getting messages and processing messages through the message loop.

3. Message processing: The message loop is responsible for distributing the message to the relevant window using the associated window procedure function for processing.



99. What is a message map?

A: Message mapping is the process of having a programmer specify an MFC class (a class with message processing power) to handle a message. The programmer then completes the writing of the processing function to implement the message processing function.



100. What is the difference between UDP and TCP?

A: TCP is all called Transmission Control protocol. This protocol can provide connection-oriented, reliable, point-to-point communication.

The UDP full name is the user message protocol, which can provide non-connected unreliable point-to-multipoint communication. With TCP or UDP, it depends on which aspect of your program do you focus on? Is it reliable or fast?

C + + face question continued

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.