文思c++笔试题目

进修社 人气:1.93W

答题

文思c++笔试题目

1、什么是纯虚函数,什么是抽象类

2、你对stl了解吗?说下vector的是如何访问元素的。

3、构造函数能够设为私有吗?

4、类的静态成员怎么初始化?const和defined的区别?

5、你对MFC了解吗?WM_SIZE消息在创建对话框的'时候被响应了几次?

6、你对数据结构了解吗?说说几种排序算法?

7、postmessage和Sendmessage的区别

8、说说对com的认识。

9、你对qt了解不?

程序题

char str[20]=”hello world”;(具体字符串是什么不知道,类似就是)

char *p = str;

int n = 18;

sizeof(str) = ______; sizeof(p) = ______; sizeof(n) = ______; strlen(str) = ______.

Void saas(char str[100])

{

Cout<

}

2.简述左 右的优缺点:

For(int k=0; k<10; k++)

{

If(condion == TRUE)

Doaa();

Else

Dobb();

K++;

}

If(condion != false)

{

For(int k=0; k<10; k++)

{

Doaa();

}

}

Else

{

For(int k=0; k<10; k++)

{

Doaa();

}

K++;

}

3.引用传递和值传递的区别,各在什么情况下使用。

4. const有什么用途?(至少说明两种,举例)

5. 判断下面程序的运行结果

void GetMemory(char *p)

{

p = (char *)malloc(100);

}

void Test(void)

{

char *str = NULL;

GetMemory(str);

strcpy(str, ”hello world”);

printf(str);

}

:程序崩溃。

因为GetMemory 并不能传递动态内存,Test 函数中的 str 一直都是 NULL。strcpy(str, ”hello world”);将使程序崩溃。

char *GetMemory(void)

{

char p[] = ”hello world”;

return p;

}

void Test(void)

{

char *str = NULL;

str = GetMemory();

printf(str);

}

可能是乱码。因为GetMemory 返回的是指向“栈内存”的指针,该指针的地址不是 NULL,但其原现的内容已经被清除,新内容不可知。

Void GetMemory2(char **p, int num)

{

*p = (char *)malloc(num);

}

void Test(void)

{

char *str = NULL;

GetMemory(&str, 100);

strcpy(str, ”hello”);

printf(str);

}

(1)能够输出hello(2)内存泄漏

void Test(void)

{

char *str = (char *) malloc(100

strcpy(str, “hello”);

free(str);

if(str != NULL)

{

strcpy(str, “world”);

printf(str);

}

}

6.输出结果

class baseq

{

public:

virtual Print()

{

cout<<”base ”<

}

void doprint()

{

Print();

}

};

class ch1:public baseq

{

public:

virtual Print()

{

cout<<”ch1 ”<

}

};

class ch2:public baseq

{

public:

virtual Print()

{

cout<<”ch2 ”<

}

};

void Doprint(baseq *bb)

{

bb->doprint();

}

void main()

{

baseq* b=new baseq;

ch1* c1=new ch1;

ch2* c2=new ch2;

Doprint(b);

Doprint(c1);

Doprint(c2);

delete b;

b=c1;

b-> Print();

b=c2;

b-> Print();

delete c1;

delete c2;

}

7.画图简单说明下进队和出队的过程

8.给出一有头结点的双向链表,要求删除链表的第n个节点,满足的条件是第n个节点的bvalue > n*n 并且 intx <= n+1.

Struct TNode

{

TNode *preHeader;

TNode *pNextNode;

double bvalue;

int intx;

};