founder面试题

1.写出正面程序支行结果:
#include<iostream>
using namespace std;
void func(int a)
{
    static int c = a;
    c++;
    cout << c << endl;
}

void main()
{
    func(15);
    func(17);
}
结果:16
     17

2.对于正面代码,请写出运行结果:
#include<iostream>
using namespace std;
class A{
public:
    virtual void func1(){ cout << "A::func1" << endl; }
    void func2(){ cout << "A::func2" << endl; };
};
class B :public A
{
public:
    void func1(){ cout << "B::func1" <<endl; }
    void func2(){ cout << "B::func2" << endl; }
};
void main()
{ 
    B x;
    B* pB = &x;
    A* pA = &x;
    pB->func1();//调用的是哪个方法
    pB->func2();//调用的是哪个方法
    pA->func1();//调用的是哪个方法
    pA->func2();//调用的是哪个方法
}
结果:
B::func1
B::func2
B::func1
A::func2
3.字节对齐:
#include<iostream>
using namespace std;
struct A{
    bool bA1;
    bool bA2;
    int nA;
    bool bA3;
};
struct B{
    bool bB1;
    bool bB2;
    bool bB3;
    int nB;
};
void main()
{
    cout << sizeof(A) << endl;
    cout << sizeof(B) << endl;
}
结果:
12
8
原文地址:https://www.cnblogs.com/timssd/p/4088547.html