1. ## array question!

hi,...just wanted to know that how would the output of the following question is coming out to be..65480 and 65496....if it is given that the array begins at 65472.
hope some1 can help me in understanding this!!!the question is :
Code:
```main()
{
int a[3][4]=
{
1,2,3,4,
4,3,2,1,
7,8,0,0
};
printf("\n%u %u",a+1,&a+1);
}```

2. Why don't you solve it yourself? Print the address of each element of the array, and print out the sizeof an integer.

Quzah.

3. Code:
```   printf("\n%u %u",a+1,&a+1);
/*
[545 Warning] Suspicious use of &
[626 Warning] argument no. 2 inconsistent with format
[626 Warning] argument no. 3 inconsistent with format
*/```
%u is used with an unsigned int.
%p is used with a pointer (to void*).
%d is used with an int.

4. i'm not being able to understand the logic behind it's output?...that how did that come and what would be the ouptput if we just mention the name of the array and when we use & with the name of array,i know it prints the adrress of an array,but isn't that print the address like the base address of an array...?then why is it printing that as its output?i couldn't understand...can some1 plz help me out there... ...

5. Try this for a bit.

6. i'm sorry....couldn't understand,,....badly need a help plz!!!!!!!

7. You need to understand data types.

This maybe isn't the best, but have a go at it.
Code:
```#include <stdio.h>

int main()
{
int a[3][4]=
{
{1,2,3,4},
{4,3,2,1},
{7,8,0,0},
};

/* A supporting cast of characters (ooh, the puns). */
int (*x)[4] = a;
int (*y)[3][4] = &a;

unsigned long sa = sizeof a;
unsigned long sx = sizeof *x;
unsigned long sy = sizeof *y;

/* A fixed version of the original. */
printf("%p %p %p\n", (void*)a, (void*)(a + 1), (void*)(&a + 1));

/* Show that all three have or point to the same location. */
printf("%p %p %p\n", (void*)a, (void*)x, (void*)y);

/* Show how big each is. */
printf("sa = %lu (0x%X), sx = %lu (0x%X), sy = %lu (0x%X)\n",
sa, sa, sx, sx, sy, sy);

/* So incrementing the starting location by the size of an object is... */
printf("%p %p %p\n", (void*)a, (void*)(x + 1), (void*)(y + 1));

return 0;
}

/* my output
0012FF54 0012FF64 0012FF84
0012FF54 0012FF54 0012FF54
sa = 48 (0x30), sx = 16 (0x10), sy = 48 (0x30)
0012FF54 0012FF64 0012FF84
*/```

8. couldn't understand properly,i'm confused now,i guess it would be better if u plz explain me through my example about the way it has reached to the output..of 65480 65496 if the array begins at 65472.....

9. Originally Posted by galmca
couldn't understand properly,i'm confused now,i guess it would be better if u plz explain me through my example about the way it has reached to the output..of 65480 65496 if the array begins at 65472.....
Hmm. Values respectively 8 and 24 past the start?

Well, it might have something to do with the sizes of integers, arrays of integers, and arrays of arrays of integers.

10. > printf("\n%u %u",a+1,&a+1)

Ok, a+1 first
a is the array name, which in this context is a pointer to the first element of the array, that being &a[0]
Since pointer arithmetic always uses the size of the object the pointer is pointing to (in this case, it's "pointing" to an array of 4 ints (the minor dimension)), a+1 is really the same as &a[1]
The result of this is a+1 (or &a[1]) is 8 bytes away from the start of the array.

Now for &a+1
Rather than pointing to the first element, this is a pointer to the whole array (who's size is 3 * 4 * sizeof(int) - which I guess is 2 on your system). This results in 24 bytes away.