为您找到"

main() { int a[5] = {1,2,3,4,5}; int *ptr =

"相关结果约100,000,000个

c - int *ptr = (int*) (&a + 1); - Stack Overflow

int *ptr = (int*)(&a + 1); // what happen here ? The address of the array is taken, and then 1 is added to it, which produces a pointer pointing sizeof a bytes past the beginning of a.That pointer is then cast to an int*, and that is assigned to ptr.The same could be achieved with

int *ptr=(int *)(&a+1) - CSDN博客

3. (int*)(&a+1) 将&a+1的地址转换成int类型的指针,即指向下一个int类型变量的指针。4. 最后将这个指针赋值给ptr。需要注意的是,这段代码涉及到指针的类型转换,如果不小心使用可能会导致不可预料的结果。

Output of C programs | Set 31 (Pointers) - GeeksforGeeks

2. Description: It is possible to assign an array to a pointer. so, when ptr = a; is executed the address of element a[0] is assigned to ptr and *ptr gives the value of element a[0]. When *(ptr + n) is executed the value at the nth location in the array is accessed. Question 2 What will be the output?

main() { int a[5] = {1,2,3,4,5}; int *ptr - 百度知道

这题的关键在int *ptr=(int *)(&a+1);这一句上,&a表示取得数组a存储区域的首地址,再加1表示数组a存储区域的后的地址,这就使得ptr指针指向数组的最后一个元素后面的那个存储单元的地址,而ptr减1后,再进行数据访问,则访问的是ptr指针的前一个存储单元的值,所有最后的答案是2,5

数组名 int a[5] = {1,2,3,4,5}; int *ptr = (int *)( &a + 1); - CSDN博客

这个问题的关键是理解 &a a是一个数组名,也就是数组的首地址。对a进行取地址运算符,得到的是一个指向数组的指针!!!!这句话尤为重要!也就相当于int (*p) [5] = &a;p是一个指针,它指向的是一个包含5个int元素的数组!那么执行p+1后,p的偏移量相当于 p + sizeof(int) * 5 !

int *ptr1=(int *)(&a+1)数组指针_int *ptr=(int*)(&a+1)-CSDN博客

这段代码将数组a的地址加1,得到的地址强制转换为int类型指针,赋值给ptr1指针。这里加1操作实际上是让指针指向数组a的下一个位置,也就是a数组之后的位置,而不是a数组的最后一个元素。由于&a是数组a的地址,因此&...

int a[5] = {1,2,3,4,5); - Brainly

int main() {int a[5] = {1,2,3,4,5); int *ptr = (int*)(&a+1); printf("%d %d", *(a+1), *(ptr-1)); return 0;} See answer Advertisement Advertisement akreddy2004 akreddy2004 Answer:, 0 is the output. Explanation: I think it is hope but arrived the zero is the correct answer and the percent b is equals to zero has multiplied to 1 ...

main() { int a[5]={1,2,3,4,5}; int *ptr=(int *)(&a+1); &_百度教育

所以prt-1只会减去sizeof(int*)a,&a的地址是一样的,但意思不一样,a是数组首地址,也就是a[0]的地址,&a是对象(数组)首地址,a+1是数组下一元素的地址,即a[1],&a+1是下一个对象的地址,即a[5]. 22.{pcurrent->next = p1 ;pcurrent = p1 ;p1 = p1->next ;}else{pcurrent->next = p2 ;pcurrent = p2 ;p2 = p2->next ...

main () {int a [5]= {1,2,3,4,5};int *ptr= (int *) (&a+1);printf ("%d,%d ...

main(){int a[5]={1,2,3,4,5};int *ptr= ... 解析. 答:2,5 *(a+1)就是a[1],*(ptr-1)就是a[4], 执行结果是2, 5。&a+1不是首地址+1,系统会认为加一个a数组的偏移,是偏移了一个数组的大小(本例是5个int)。int *ptr=(int *)(&a+1); 则ptr实际是&(a[5]),也就是a+5. 原因如下:

下面函数的运行结果是什么?main () {inta [5]= {1,2,3,4,5};int*ptr= (int*) (&a+1 ...

解析:2,5*(a+1)就是a[1],*(ptr-1)就是a[4], 执行结果是2, 5。&a+1不是首地址+1,系统会认为加一个a数组的偏移,是偏移了一个数组的大小(本例是5个int)。int *ptr=(int *)(&a+1); 则ptr实际是&(a[5]),也就是a+5

相关搜索