77范文网 - 专业文章范例文档资料分享平台

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

来源:网络收集 时间:2019-07-29 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

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

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库C++语言面试宝典(3)在线全文阅读。

C++语言面试宝典(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/jiaoyu/665633.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: