指针与数组

对于下面的代码,说法正确的是____。
1
2
3
4
5
6
char* s1 = "Hello world";
char s2[] = "Hello world";
s1[2] = 'E';     // 1
s2[2] = 'E';     // 2
*(s1 + 2) = 'E';  // 3
*(s2 + 2) = 'E';  // 4

 

指针指向字符串时,字符串是常量,存储在常量区,而指针存储在栈区,不能对其操作修改。

 

求输出结果 

1
2
3
int a[2][2][3]= { {{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}}};
int *ptr=(int *)(&a+1);
printf(“%d %d”, *(int*)(a+1), *(ptr-1));

 

1
2
1. &a+i = a + i*sizeof(a); 
2. a+i = a +i*sizeof(a[0]);  

posted on 2017-04-01 17:23  时间的女儿  阅读(126)  评论(0编辑  收藏  举报

导航