C++语言面试宝典(3)
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
相关推荐:
- [综合文档]应答器设备技术规范(征求意见稿)A1
- [综合文档]教师 2012年高考政治试题按考点分类汇
- [综合文档]保险公司的总经理助理竞职演说
- [综合文档]卫生应急大练兵大比武活动考试--题库(
- [综合文档]徐州经济技术开发区总体规划环境影响报
- [综合文档]汉语拼音表(带声调)
- [综合文档]二年级 上 思维训练( 1~18)
- [综合文档]特色学校五年发展规划
- [综合文档]机床经常出现报警“X1轴定位监控”
- [综合文档]《电子技术基础》21.§5—2、3、4 习题
- [综合文档]浙江省深化普通高中课程改革
- [综合文档]CRISP原理 - 图文
- [综合文档]2017年电大社会调查研究与方法形考答案
- [综合文档]浅析建筑施工安全毕业论文
- [综合文档]《回忆我的母亲》名师教案
- [综合文档]装饰装修工程监理规划
- [综合文档]三下乡心得体会-文艺
- [综合文档]柱计算长度系数 - 图文
- [综合文档]全流程思考,提高燃电系统热电转换率--
- [综合文档]2018年嘉定区中考物理一模含答案
- 433M车库门滚动码遥控器
- 8、架空线路施工规范
- 大学四年声乐学习的体会
- 新北师大版五年级数学上册《轴对称再认
- 部编版五年级上册语文第六单元小结复习
- 小学六年级英语形容词用法
- 第2课 抗美援朝保家卫国 课件01(岳麓版
- 2015年天津大学运筹学基础考研真题,考
- 微机计算机控制技术课后于海生(第2版)
- 安全教育实践活动
- Delphi程序设计教程_第1章_Delphi概述
- 第八讲 工业革命与启蒙运动
- 《中华人民共和国药典》2005年版二部勘
- 科粤版九年级化学2.3构成物质的微粒(1)
- 西师大版数学三年级下册《长方形、正方
- ch6_冒泡排序演示
- 第4章 冲裁模具设计
- 浙江中小民营企业员工流失论文[终稿]
- 再议有线数字电视市场营运模式
- 昆明供水工程监理大纲




