Thread: (array+ 1 ) and (&array+1) diff ?

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    New York
    Posts
    24

    (array+ 1 ) and (&array+1) diff ?

    Hi,

    name of array gives us the base address always.
    so, in the code below:

    Code:
    int arr[]={1,2,3};
    printf("%p:%p", arr+1,&arr+1);
    we should get out put as

    22220104: 22220104 (if the base address is 22220100).
    But why it is 22220104:22220112.

    Thanks and regards,
    A
    Last edited by Alexpo; 06-23-2008 at 01:48 AM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Adding one to a pointer advances that pointer by the size of the thing pointed to.

    arr points to an int, so it advances 4 (sizeof int on your system).

    &arr points, not to an int, but to an int[3]. The size of an int[3] is 12, so twelve bytes are added.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf( "%s", &array )
    By Else in forum C Programming
    Replies: 19
    Last Post: 09-15-2008, 02:04 PM
  2. sizeof pointer-to-array -- &array
    By josemariasola in forum C Programming
    Replies: 19
    Last Post: 07-15-2006, 06:39 PM