|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
关于指针和指针数组和数组的问题。
例:
int ch1[5] = {10, 20, 30, 40, 50};
int ch2[5] = {100, 200, 300, 400, 500};
int ch3[5] = {1000, 2000, 3000, 4000, 5000};
int *ch[1024] = {ch1, ch2, ch3};
printf("ch1 = %p\n", ch1);
printf("ch[0] = %p\n", ch[0]);
printf("ch[1] = %p\n", ch[1]);
printf("ch[2] = %p\n", ch[2]);
printf("ch1+1 = %p\n", ch1+1);
printf("ch[0]+1 = %p\n", ch[0]+1);
printf("ch[1]+1 = %p\n", ch[1]+1);
printf("ch[2]+1 = %p\n", ch[2]+1);
printf("*ch1 = %d\n", *ch1);
printf("*(ch[0]) = %d\n", *(ch[0]));
printf("*(ch[1]) = %d\n", *(ch[1]));
printf("*(ch[2]) = %d\n", *(ch[2]));
printf("*(ch1+1) = %d\n", *(ch1+1));
printf("*(ch[0]+1) = %d\n", *(ch[0]+1));
printf("*(ch[1]+1) = %d\n", *(ch[1]+1));
printf("*(ch[2]+1) = %d\n", *(ch[2]+1));
putchar('\n');
printf("ch = %p\n", ch);
printf("*ch = %p\n", *ch);
printf("ch+1 = %p\n", ch+1);
printf("*ch+1 = %p\n", *ch+1);
putchar('\n');
printf("**ch = %d\n", **ch);
printf("**(ch+1) = %d\n", **(ch+1));
printf("*(*ch+1) = %d\n", *(*ch+1));
putchar('\n');
执行结果为:
ch1 = 0xbfc5eeb8
ch[0] = 0xbfc5eeb8
ch[1] = 0xbfc5eea4
ch[2] = 0xbfc5ee90
ch1+1 = 0xbfc5eebc
ch[0]+1 = 0xbfc5eebc
ch[1]+1 = 0xbfc5eea8
ch[2]+1 = 0xbfc5ee94
*ch1 = 10
*(ch[0]) = 10
*(ch[1]) = 100
*(ch[2]) = 1000
*(ch1+1) = 20
*(ch[0]+1) = 20
*(ch[1]+1) = 200
*(ch[2]+1) = 2000
ch = 0xbfc5de90
*ch = 0xbfc5eeb8
ch+1 = 0xbfc5de94
*ch+1 = 0xbfc5eebc
**ch = 10
**(ch+1) = 100
*(*ch+1) = 20
求问**(ch+1) 为什么等于100,应该等于2000?还是等于其他??????? |
|