各大公司c++面试题
各大企业面试题3.main主函数履行结束后,是不是可能会再履行一段代码?(朗讯的一道笔试题)答案:可以,可以用_onexit注册一个函数,它会在main以后履行;
假如你需要加入一段在main退出后履行的代码,可以使用atexit()函数,注册一个函数。
语法:
#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.多态类中的虚函数表是Compile-Time,仍是Run-Time时建立的?答案:虚拟函数表是在编译期就建立了,各个虚拟函数这时被安排成了一个虚拟函数的进口地址的数组.而目标的隐藏成员--虚拟函数表指针是在运行期--也即是结构函数被调用时进行初始化的,这是实现多态的重要.
4.一个父类写了一个virtual函数,假如子类覆盖它的函数不加virtual,也能实现多态?
在子类的空间里,有没有父类的这个函数,或许父类的私有变量?(华为笔试题)答案:只要基类在定义成员函数时已经声明晰virtue重要字,在派生类实现的时候覆盖该函数时,virtue重要字可加可不加,不影响多态的实现。子类的空间里有父类的所有变量(static在外)。
2)类ClassB从ClassA派生,那么ClassA
a=newClassB(…);试问该表达是不是合法?为什
么?
c++理论方面的题.doc
c言语方面.doc
.....太多文件了略.....
(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 .....)
页:
[1]