华为程序员面试笔试试卷 一、推断题(对的写 T,错的写 F 并说明原因,每小题 4 分,共 20 分) 1、有数组定义 int a[2][2]={{1},{2,3}};则 a[0][1]的值为 0
( 正确 ) 2、int (*ptr) (),则 ptr 是一维数组的名字
( 错误 int (*ptr) ();定义一个指向函数的指针变量 ) 3、指针在任何情况下都可进行, ,=, =,==运算
( 错误 ) 4、switch(c) 语句中c可以是int ,long,char ,float ,unsigned int 类型
( 错,不能用实形 ) 二、填空题(共 30 分) 1、在 windows 下,写出运行结果,每空 2 分,共 10 分
char str[ ]= Hello; char *p=str; int n=10; sizeof(str)=( ) sizeof(p)=( ) sizeof(n)=( ) void func(char str[100]){ } sizeof(str)=( ) 答 案 :6,4,4,4, 具体解释请参看我的空间里的“C/C++程序员应聘试题剖析” 2、void getmemory(char **p, int num) { *p=(char *) malloc(num);} void test(void) { char *str=NULL; getmemory(str,100); strcpy(str,hello); printf(str); } 运行 test 函数有什么结果
( )10 分 答案:输出 hello,但是发生内存泄漏
3、设 int arr[]={6,7,8,9,10}; int *ptr=arr; *(ptr++)+=123; printf(%d,%d,*ptr,*(++ptr)); ( ) 10 分 答 案 :8