在面试C/C++相关的岗位时,sizeof操作符几乎是必考内容,它能检验面试者的基本功,所以,只能全对,不能出错。
一起来看看,这些题目,你能全做对吗?说明:如下题目是基于64位平台。
1. sizeof(基本类型)
#include<iostream>#include<cstring>using namespace std;void fun1(char str[20]){cout << sizeof(str) << endl;}void fun2(char a[10][9]){cout << sizeof(a) << endl;}int func3(){cout << "hello world" << endl;return 0;}int main(){cout << sizeof(int) << endl; // 4cout << sizeof(long) << endl; // 8int i = 0;cout << sizeof(++i) << endl; // 4cout << i << endl; // 0, 注意不是1哦cout << sizeof(func3()) << endl; // 4, 注意没有hello world打印哈char *p1;cout << sizeof(p1) << endl; // 8int *p2 = new int[100];cout << sizeof(p2) << endl; // 8delete [] p2;float *p3;cout << sizeof(p3) << endl; // 8double ******p4;

本文聚焦于C/C++面试中常见的sizeof操作符,探讨了sizeof在处理基本类型和复合类型时的运用。文章适用于64位平台,通过一系列题目考察读者对sizeof的理解,帮助他们在笔试面试中提升自信,顺利拿到理想的工作机会。
1万+

被折叠的 条评论
为什么被折叠?



