今天无聊在网上搜了下今年各大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 *= ;
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 *= ;
func2();
}
protected:
void func2()
{
i += ;
}
}; int main()
{
Base *pb = new Child();
pb->func1();
cout << pb->getValue() << endl;
delete pb; return ;
}
2.程序的输出结果:
#include <stdio.h>
#define DOUBLE(x) x + x void main()
{
int i = DOUBLE() * ;
printf("%d\n", i);
}
3. 程序的输出结果:
#include <stdio.h> int main()
{
char num; for(num = ; num < ; )
{
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 ;
}
5. x86_64环境下
#include <stdio.h> int main()
{
int a[][] = {
{, , , },
{, , , },
{, , , },
{, , , }
}; int (*p1)[] = a;
int (*p2)[] = &a[];
int *p3 = &a[][]; printf("%d, %d, %d, %d\n",
*(*(a + ) - ),
*(*(p1 + ) - ) + ,
*(*(p2 - ) + ) + ,
*(p3 + sizeof(p1) - )); printf("%d\n", sizeof(p1)); return ;
}
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 ;
}
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语言都忘的差不多了,特别是指针,如果理解的麻烦给我解释下,谢谢啦!