(Big company interview questions
3. After the execution of the main main function, is it possible to execute another piece of code? (a written test question from Lucent) Answer: Yes, you can use _onexit to register a function, and it will be executed after main;
If you need to add a piece of code that executes after main exits, you can use the atexit() function to register a function.
grammar:
#includelt;stdlib.hgt;
intatexit(void(
function)(void));
#includelt;stdlib.hgt;
#includelt;stdio.hgt;
voidfn1(void),fn2(void),fn3(void),fn4(void);
intmain(void)
{
atexit(fn1);
atexit(fn2);
atexit(fn3);
atexit(fn4);
printf(Thisisexecutedfirst.\n);
}
1. Is the virtual function table in a polymorphic class Compile-Time, or is it created during Run-Time? Answer: The virtual function table is created at compile time, and each virtual function is arranged as a virtual function at this time. An array of import addresses. And the hidden member of the target - the virtual function table pointer is initialized at runtime - that is, when the structure function is called, which is important to achieve polymorphism.
4. A parent class writes a virtual function. If the subclass overrides its function without adding virtual, can it also achieve polymorphism?
In the space of the subclass, is there this function of the parent class, or a private variable of the parent class? (Huawei written test) Answer: As long as the base class has declared the important word of virtual when defining member functions, when the derived class implements it When overriding this function, the important words of virtual can be added or not, which does not affect the realization of polymorphism. The space of the subclass has all the variables of the parent class (static outside).
2) Class ClassB is derived from ClassA, then ClassA
a=newClassB(…); Is this expression legal? Why
what?
C theoretical questions.doc
c language.doc
.....too many files .....)