教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 综合文档 >

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

来源:网络收集 时间:2026-02-19
导读: 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

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

…… 此处隐藏:976字,全部文档内容请下载后查看。喜欢就下载吧 ……
C++语言面试宝典(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/402904.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)