为您找到"
...main(void) { int a[][3] = {1,2,3,4,5,6}; int (*ptr)[3] = a...
"相关结果约100,000,000个
@AnT I am expecting the output as "2 3 3 4" because I think initially the ptr is pointing to the first row of double dimensional array "a". Therefore (*ptr)[1] of first printf will give us 2, like wise (*ptr)[2] will give us 3.But after the ++ptr line it will start pointing to the second element of the first row of a[][3].Therefore (*ptr)[1] of second line should now give us 3 and likewise ...
QUESTION C The correct answer for the given question is option a: 2 3 5 6 Given an array a of 2-dimensional with number of columns 3 and number of rows isn't specified. As array a is declared with values {1,2,3,4,5,6}, hence 1st row of array cont …View the full answer
这题的关键在int *ptr=(int *)(&a+1);这一句上,&a表示取得数组a存储区域的首地址,再加1表示数组a存储区域的后的地址,这就使得ptr指针指向数组的最后一个元素后面的那个存储单元的地址,而ptr减1后,再进行数据访问,则访问的是ptr指针的前一个存储单元的值,所有最后的答案是2,5
&a-----int(*)[5](类型),如果要将&a赋值给p,则有int (*p)[5] = &a &a是数组的地址,&a+1跳过整个数组 将&a+1强制类型转换为和指针变量ptr相同的类型,ptr-1表示减去一个整型的地址 *(a+1):a是数组名,表示首元素地址,a的类型为(int*),如图a位置,加1表示跳过一个元素,指向2的位置,如图a+1,解引用后值为2。
If you are a beginner and unsure of certain basic things, it is good to write a program and infer the results. It will also helps you to understand as well as code efficiently. a[1][2] is 6. Here is your sample program:
6 int (*ptr)[3] = a;//定义一个指针指向数组,记住,ptr指向的是一个二维数组,也就是ptr增一, 7 //那么就相当于a这个二维数组的第一个下标增一,我觉得你不明白的就是这
#include int main() { int a[][3] = {1, 2, 3, 4, 5, 6}; int (*ptr)[3] = a; printf("%d %d ", ... (b) 2 3 4 5 (c) 4 5 0 0 (d) none of the above
int a[] = {1,2,3,4,5,6}; 则int (*ptr) = a; int *p = a[0] 有什么区别 int (*ptr) 和int *p 本身是没有什么区别的,都是定义一个指针 只不过名字叫的不同而已,a表示数组的首地址,确切的说法应该是数组的第1个元素的地址,即在这里是a[0]的地址 . int *p = a[0]不能表达正确意思。
int (*p)[10] is a pointer to an array of 10 integers in each row i.e there can be any number of rows. basically it can be used to point to a 2D array and the dimensions can be accessed by incrementing i for *(p+i)[10] which is same as a[i][10], here 'i=1,2,3...' to access 1,2,3.. rows. where as, int *p[10] is an array of 10 integer pointers. If array is two dimesional i.e, for example
int (*ptr)[3] = a; // here ptr is pointer to an array of 3 integers. At first ptr is pointing to first row. Say address of 1st row is 2000. So, (*ptr)[1]=*(2004)=2 and (*ptr)[2]=*(2008)=3 Now ++ptr is updating pointer to next row.So, Now ptr pointing to address 2000+3*4=2012