The array's address +1 and pointer to array +1 differ

Source: Internet
Author: User

The array a[8] is defined, where a,&a,&a[0] is the starting address of the array. But there is a difference in step size, that is, different types

A is equivalent to a+0 equivalent to &a[0], which is a pointer to the first element of the array, and the step is a pointed element that occupies an address space of sizeof (int).

&a is also a pointer to the first element of the array, but its meaning is to point to the first address of the entire array, to the type as a whole array, so its step is 8*sizeof (int)

While PTR means that the pin points to the array is the first address, so * (PTR-1) The value is 8

That is, the result of the output is 8


#include <stdio.h> #include <stdlib.h> #define MAX (A,b,c) ((a+b) >c)? 1:0int Main () {int a[8]={1,2,3,4,5,6     , 7,8};     int *ptr= (int*) (&a+1);     printf ("%d%d%d%d%d\n", a,&a,&a[0],a+1,&a+1,&a[0]+1);    printf ("%d%d\n", * (ptr-1), *ptr); return 0;}


The array's address +1 and pointer to array +1 differ

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.