C++语言面试宝典(3)

2019-07-29 11:07

p2=(char*)malloc(20); memset (p2, 0, 20); while(*p2++ = *p1++); printf(“%sn”,p2); }

Answer:empty string.

What will be printed as the result of the operation below:

main() {

int x=20,y=35; x=y++ + x++; y= ++y + ++x;

printf(“%d%dn”,x,y); }

Answer : 5794

What will be printed as the result of the operation below:

main() {

int x=5;

printf(“%d,%d,%dn”,x,x< <2,x>>2); }

Answer: 5,20,1

What will be printed as the result of the operation below:

#define swap(a,b) a=a+b;b=a-b;a=a-b; void main() {

int x=5, y=10; swap (x,y);

printf(“%d %dn”,x,y); swap2(x,y);

printf(“%d %dn”,x,y); }

int swap2(int a, int b)

{

int temp; temp=a; b=a; a=temp; return 0; }

Answer: 10, 5 10, 5

What will be printed as the result of the operation below:

main() {

char *ptr = ” Cisco Systems”; *ptr++; printf(“%sn”,ptr); ptr++;

printf(“%sn”,ptr); }

Answer:Cisco Systems isco systems

What will be printed as the result of the operation below:

main() {

char s1[]=“Cisco”; char s2[]= “systems”; printf(“%s”,s1); }

Answer: Cisco

What will be printed as the result of the operation below:

main() {

char *p1; char *p2;

p1=(char *)malloc(25); p2=(char *)malloc(25);

strcpy(p1,”Cisco”); strcpy(p2,“systems”); strcat(p1,p2);

printf(“%s”,p1); }

Answer: Ciscosystems

The following variable is available in file1.c, who can access it?:

static int average;

Answer: all the functions in the file1.c can access the variable.

What will be the result of the following code?

#define TRUE 0 // some code while(TRUE) {

// some code }

Answer: This will not go into the loop as TRUE is defined as 0.

What will be printed as the result of the operation below:

int x;

int modifyvalue() {

return(x+=10); }

int changevalue(int x) {

return(x+=1); }

void main() {

int x=10; x++;

changevalue(x); x++;

modifyvalue();

printf(\ x++;

changevalue(x);

printf(\modifyvalue();

printf(\ }

Answer: 12 , 13 , 13

What will be printed as the result of the operation below:

main() {

int x=10, y=15; x = x++; y = ++y;

printf(“%d %dn”,x,y); }

Answer: 11, 16

What will be printed as the result of the operation below:

main() {

int a=0; if(a==0)

printf(“Cisco Systemsn”); printf(“Cisco Systemsn”); }

Answer: Two lines with “Cisco Systems” will be printed.

再次更新C++相关题集

1. 以下三条输出语句分别输出什么?[C易]

char str1[] = \char str2[] = \const char str3[] = \const char str4[] = \const char* str5 = \const char* str6 = \

cout << boolalpha << ( str1==str2 ) << endl; // 输出什么? Cout << boolalpha << ( str3==str4 ) << endl; // 输出什么? Cout << boolalpha << ( str5==str6 ) << endl; // 输出什么?

13. 非C++内建型别 A 和 B,在哪几种情况下B能隐式转化为A?[C++中等] 答:

a. class B : public A { ??} // B公有继承自A,可以是间接继承的 b. class B { operator A( ); } // B实现了隐式转化为A的转化

c. class A { A( const B& ); } // A实现了non-explicit的参数为B(可以有其他带默认

值的参数)构造函数

d. A& operator= ( const A& ); // 赋值操作,虽不是正宗的隐式类型转换,但也可以勉

强算一个

12. 以下代码中的两个sizeof用法有问题吗?[C易]

void UpperCase( char str[] ) // 将 str 中的小写字母转换成大写字母 {

for( size_t i=0; i

char str[] = \

cout << \字符长度为: \UpperCase( str ); cout << str << endl;

7. 以下代码有什么问题?[C难]

void char2Hex( char c ) // 将字符以16进制表示 {

char ch = c/0x10 + '0'; if( ch > '9' ) ch += ('A'-'9'-1); char cl = c%0x10 + '0'; if( cl > '9' ) cl += ('A'-'9'-1); cout << ch << cl << ' '; }

char str[] = \中国\

for( size_t i=0; i


C++语言面试宝典(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:超细玻璃棉项目可行性研究报告 - 图文

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: