C/C++ job book 21 key notes (often written test interview points)

Label Job wantedInterviewWritten examinationC language
3670 people reading comments(3) Collection Report
Classification:
1 char c ='\72'; \72 represent in a character, 72 is an octal number, representing the ASCII character code":".

2 10*a++ a in the first multiplication then increment (written in love often output problems of this kind of operator precedence confusing).

The role of static and 3 const


The less common problem, below give a detailed answer:

The static keyword:

1) the scope of the in vivo function of static variables as a function of body. Different from the auto variable. The variable memory is assigned only once. Therefore its value remained the last value in the next call.

2) static global variables in the module can be any function module access. But not by other function module access.

3) static function in the module can only be called by other functions within this module. Use this function is limited in its statement module.

4) in the static members of the class belongs to the class of all variables, all object class only one copy.

5) the static member function in the class belongs to the class of all, this function does not accept the this pointer, which can only access the class member variables static.

The const keyword:

1) to prevent a variable is changed, you can use the const keyword. In the definition of the const variable, you need to initialize it. Since there is no chance to change it.

2) to a pointer, the pointer itself can be specified for the const, you can also specify the pointer to const. At the same time as const or two.

3) in a function declaration, const can modify the parameters, show that it is an input parameter. Cannot change its value within the function.

4) for a class member function, if designated as const type. That is a constant function. Cannot modify the member variables of a class.

5) for the member functions of the class, sometimes you must specify the type of the return value is const. The return value is not an lvalue to make it".


4 note that sizeof is not a function but operator, so the calculation of the variable space hour, parentheses can be omitted, but in the calculation of type size brackets cannot be omitted, such as the int i = 0; sizeof int is wrong.

5 1,2,... N, a disorderly array, for sorting algorithm, and the time complexity is O (n), the space complexity of O (1), the use of exchange, but one can only exchange the number two.



6 misleading: if int a[5], then a and &a are equivalent, because both the same address.
Answer: be sure to is not the same as to note that a and &a. Although both addresses are the same, but the meaning is not the same, &a is the first address of the array object and a is the first address in the array, also is a[0] address and the type of a is int[5], a[0] type int, so &a+1 quite a address value plus sizeof (int) * 5, that is a[5], the address of an object, have cross-border the, and a + 1 is equivalent to a's address on the sizeof (int), namely a [1] address.

7 how to convert a decimal into integer and fractional parts?

Remember to use the library function MODF header files, here is the prototype (remember some practical library functions, avoid rewriting):



Double MODF (double num, double *i); / / num is decomposed into integer and fractional part of *i (return value)
8 can be used as the basis to judge the function overloading: the number of parameters, parameter types, const modifier;
Not as heavy judgment: return type.

9 output problem:

Int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Int & *p = (a + 1) [3];

Printf (%d\n, *p);


Output: 5
Note: because a+1 refers to a second elements, [3] said to move back 3 elements.

10 output problem:


Output: 0011
Note: output str1~str8 address:


Memory address str1~str8 output "ABC" for:


Can be found in the str1~str4 content is on the stack, the address is different, and the contents of str5~str8 are stored in the constant region, so are the same.

Be careful


The above is to print the string "ABC" is the STR1 address, print the following variables.

The difference between the structure and the structure of C++ 11 C.

(1) C in the structure does not allow function exists, C++ allows the internal member functions, and allows the function is virtual. So the C structure is not a constructor, destructor, and this pointer.
(2) access only on the internal structure of C member variables are public, C++ and protected, private allows public, three.
(3) the structure of the C language can not be inherited, the structure of C++ can be inherited from other structures or classes over.
All of the above surface difference, the difference is the difference between the actual process oriented and object-oriented programming ideas:

C is the data structure variables to wrap up, does not involve the algorithm.
C++ is the data variables and related algorithms on these data variables to encapsulate and give these data and different access permissions.

C language is not the concept of the class, but the C language can create a function pointer to achieve structure object oriented thinking.


How about 12 in the definition of class members and for its constant initialization?
Answer: only the initialization of const members in the initialization list, like this:


The following is wrong:


The following approach is not wrong, but there is a warning, is not recommended:


What is the 13 in the class when the membership function is defined using the mutable keyword?
Answer: when the data members need to modify the object in the const method, you can use the mutable keyword in the data members, prevent compiler error. Examples are as follows:


14. The constructor, copy constructor, destructor call and order problems, such as the following example output is what?


Answer: pay attention to the copy constructor in the object as a function parameter is called, attention is not the object reference object instance. So the output is as follows:


Extended copy constructor: in what circumstances is called?
(1) the value of transfer function parameters and parameters for the class object;
(2) the class object as a function return value.

Keywords explicit 15 C++ in what role?
Answer: prohibit the constructor as transfer function, which prohibits the constructor automatically implicit type conversion.
For example, only one parameter m_price in CBook, you can use the CBook C = 9.8 this implicit conversion in the construction object, the use of explicit to prevent the conversion.

In C++ 16, to determine if a constructor in the constructor in the creation process, if you call the other overloaded constructor, it will not perform any other constructor initializer list part of the code, but perform the function code, this has degenerated into a common function. Examples are as follows:


17 static data member can only be initialized in the global area, but not in the class body (the constructor initialization is not), and static data members do not involve the object, therefore not subject to access restrictions qualifier.
Examples are as follows:


18 C++ operators can be overloaded: new/delete, new[]/delete[] + +, etc..
The operator can not overloaded:,.,,::: sizeof, typeID, and?., * *, can not change the priority of the operator.

Extended overloading + + and - is how to distinguish between the prefix and postfix + + + +?
For example, when the compiler sees ++a (Xian Zizeng), it is called operator++ (a);
But when the compiler sees a++, it is called operator++ (a, int). The compiler function by calling the differences between these two forms.

The polymorphism of 19 C++ were divided into static polymorphism and dynamic polymorphism.
Static polymorphism: to determine which specific implementation operation during compilation, is mainly achieved through function overloading and operator overloading;
Dynamic polymorphism: to determine which specific implementation operation, is mainly achieved through the virtual function.

20 virtual function principle test, such as what is the output of the following program?


Q: sizeof (A) =?

Answer
A kind of memory space occupied, the following points need attention:
(1) if there is a virtual function class, the compiler needs for constructing the virtual function table, the need to store a pointer to the first address of the virtual function table class, pay attention to whether there are several virtual functions, only a table, a virtual function address all exist in the list class only need a pointer to the first address of the virtual function table.
(2) static members of the class are shared by all instances of the class, it is not included in the calculation of sizeof space
(3) in the class of ordinary function or static ordinary functions are stored in the stack, not included in the calculation of sizeof space
(4) class members using the allocated space byte aligned mode

Answer: 12 (32 bit) or 16 (64 bit)

What is the role of the 21 virtual inheritance?
In multiple inheritance, the subclass may have more than one parent, if the parent class have the same parent (Zu Xianlei), so in the sub class will have multiple copies of ancestors. For example, B and C are inherited from the A, if D is derived from B and C, then it will have two copies of A in D. In order to prevent the existence of multiple inheritance in neutron parent repeated, can use a virtual function in the parent class, the class B and class C extends A when using the virtual keyword, for example:
Class B: virtual public A
Class C: virtual public A
Note: because multiple inheritance will bring a lot of complex problems, so be careful.
top
One
tread
Zero
Guess you're looking for
View comments
* the above user comments represent the personal views do not represent the views or position of the CSDN website
    personal data
    • Visit395255 times
    • Integral:Four thousand six hundred and eighty-two
    • Grade
    • Ranking:3306th
    • Original104
    • Reprint:82
    • Translation:0
    • Comment:1083
    contact us
    Contact: Yao Xi
    Tel: 51661202-381
    E-mail: yaoxi@PROG3.COM
    QQ number: 2411559571
    Club address: http://prog3.com/sbdm/student