zoukankan      html  css  js  c++  java
  • 搜狗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
    ", i);
    }

    3. 程序的输出结果:

    #include <stdio.h>
    
    int main()
    {
        char num;
    
        for(num = 0; num < 255; )
        {
            num += num;
        }
    
        printf("the num is %d
    ", 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
    ",
            *(*(a + 1) - 1), 
            *(*(p1 + 3) - 2) + 1, 
            *(*(p2 - 1) + 16) + 2, 
            *(p3 + sizeof(p1) - 3));
    
        printf("%d
    ", 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语言都忘的差不多了,特别是指针,如果理解的麻烦给我解释下,谢谢啦!

  • 相关阅读:
    个人永久性免费-Excel催化剂功能第23波-非同一般地批量拆分工作表
    个人永久性免费-Excel催化剂功能第22波-Excel文件类型、密码批量修改,补齐PowerQuery短板
    个人永久性免费-Excel催化剂功能第21波-Excel与Sqlserver零门槛交互-执行SQL语句篇
    个人永久性免费-Excel催化剂功能第20波-Excel与Sqlserver零门槛交互-数据上传篇
    json使用
    jquery 1.9版本下复选框 全选/取消实现
    SSL F5
    apache优化
    Apache 慢连接dos
    php导出数据到excel,防止身份证等数字字符格式变成科学计数的方-------缺点,必须使用table tr td
  • 原文地址:https://www.cnblogs.com/lanxuezaipiao/p/3185146.html
Copyright © 2011-2022 走看看