搜狗2013年校園招聘研發類筆試試卷之C/C++類


今天無聊在網上搜了下今年各大NB IT公司的筆試題,搜到了搜狗的,只有掃描版的試卷沒有電子版也沒有答案,就拿來做了做,題目非常多,涉及到C/C++、Java、數據結構、Android、IOS、Javascript等Web、甚至數據挖掘、綜合類,在此先公布幾道C/C++的基礎題,十分簡單當然也不是Hello World那種的,一不小心就容易犯錯。

就是一些程序輸出題:都是些基本題,學的基礎扎實的不成問題,所以大牛們就飄過吧,給那些和我一些菜鳥的人准備滴~~~

雖然是選擇題,但為了更有挑戰力,我不給出選項了,大家看看能不能全部做出來,我這有標准答案,可以回復答案,我給你們打分哈~~~

1. 程序的輸出結果:

#include <iostream>
using namespace std;

class Base {
public:
    Base(int j) : i(j) {}
    virtual ~Base() {}
    void func1()
    {
        i *= 10;
        func2();
    }
    int getValue()
    {
        return i;
    }
protected:
    virtual void func2()
    {
        i++;
    }
protected:
    int i;
};

class Child : public Base {
public:
    Child(int j) : Base(j) {}
    void func1()
    {
        i *= 100;
        func2();
    }
protected:
    void func2()
    {
        i += 2;
    }
};

int main()
{
    Base *pb = new Child(1);
    pb->func1();
    cout << pb->getValue() << endl;
    delete pb;

    return 0;
}

 

2.程序的輸出結果:

#include <stdio.h>
#define DOUBLE(x) x + x

void main()
{
    int i = DOUBLE(5) * 5;
    printf("%d\n", i);
}

 

3. 程序的輸出結果:

#include <stdio.h>

int main()
{
    char num;

    for(num = 0; num < 255; )
    {
        num += num;
    }

    printf("the num is %d\n", num);
}

 

4. 程序出錯在什么階段(編譯?運行?)還是程序正常運行呢?

#include <iostream>

using namespace std;
int main(int argc, char **argv)
{
    hhhhttp://www.sogou.com
    cout << "Welcome to sogou" << endl;
    return 0;
}

 

5. x86_64環境下

#include <stdio.h>

int main()
{
    int a[4][4] = {
        {1, 2, 3, 4},
        {50, 60, 70, 80},
        {900, 1000, 1100, 1200},
        {13000, 14000, 15000, 16000}
    };

    int (*p1)[4] = a;
    int (*p2)[4] = &a[0];
    int *p3 = &a[0][0];

    printf("%d, %d, %d, %d\n",
        *(*(a + 1) - 1), 
        *(*(p1 + 3) - 2) + 1, 
        *(*(p2 - 1) + 16) + 2, 
        *(p3 + sizeof(p1) - 3));

    printf("%d\n", sizeof(p1));

    return 0;
}

 

6. 在32位操作系統gcc編譯環境下,下面程序的運行結果為:

#include <iostream.h>

class A {
public:
    int b;
    char c;
    virtual void print() {
        cout << "this is father's function!" << endl;
    }
};

class B : A {
public:
    virtual void print() {
        cout << "this is children's function!" << endl;
    }
};

int main()
{
    cout << sizeof(A) << " " << sizeof(B) << endl;

    return 0;
}

 

7.  有如下幾個類和函數定義,幾個bar都能編譯通過嗎?哪些能通過?哪些通不過?

#include <iostream>
using namespace std;

class A
{
public:
    virtual void foo() {}
};

class B
{
public:
    virtual void foo() {}
};

class C
    :public A, public B
{
public:
    virtual void foo() {}
};

void bar1(A *pa) {
    B *pc = dynamic_cast<B *>(pa);
}

void bar2(A *pa) {
    B *pc = static_cast<B *>(pa);
}

void bar3() {
    C c;
    A *pa = &c;
    B *pb = static_cast<B *>(static_cast<C *>(pa));
}

 

大家沒事做做哈!不用跑去機器上運行一遍,浪費時間(雖然只需要復制粘貼),另外有些題我也不是很明白(真正的小菜鳥),比如第5題,本人Java學的還可以,但C語言都忘的差不多了,特別是指針,如果理解的麻煩給我解釋下,謝謝啦!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM