10、下面程序运行后的结果为:
char str[] = "glad to test something";
char *p = str;
p++;
int *p1 = reinterpret_cast<int *>(p);
p1++;
p = reinterpret_cast<char *>(p1);
printf("result is %s\n", p);
正确答案: D result is glad to test something result is ad to test something result is test something result is to test something
解析:此题问题出在没看清楚类型,char 1个字节;int 四个字节 p++; 此时在l p1++; = p+=4;此时指针在t.
最后p,指向t,打印值“to test something”
9、32位系统下下面程序的输出结果为多少?
void Func(char str_arg[100])
{
printf("%d\n",sizeof(str_arg));
}
int main(void)
{
char str[]="Hello";
printf("%d\n",sizeof(str));
printf("%d\n",strlen(str));
char*p=str;
printf("%d\n",sizeof(p));
Func(str);
}
正确答案: B 5 5 4 4 6 5 4 4 6 5 6 4 5 5 5 100
1、"Hello"自带结束符,字符长度5,内存长度6 2、,sizeof§;p是指针,指针长度都是p 3,c++中不允许隐式的数组拷贝 Func(char str_arg[100]),c++中,以数组作为函数参数传递,传递的是指针。一般要操作都还得带数组实际长度。
|