Hi,

The following code,

[code]
unsigned long x[4], y[4];

printf("Values with & operator - %08X, %08X
", &x, &y);
printf("Values without & operator - %08X, %08X
", x, y);
[/code]

prints the output,

Values with & operator - 0012FEC8, 0012FEB0
Values without & operator - 0012FEC8, 0012FEB0

Now my question is, shouldn't values of x and [b]&[/b]x be different?

TIA,
Kani

• : Hi,
:
: The following code,
:
: [code]
: unsigned long x[4], y[4];
:
: printf("Values with & operator - %08X, %08X
", &x, &y);
: printf("Values without & operator - %08X, %08X
", x, y);
: [/code]
:
: prints the output,
:
: Values with & operator - 0012FEC8, 0012FEB0
: Values without & operator - 0012FEC8, 0012FEB0
:
: Now my question is, shouldn't values of x and [b]&[/b]x be different?
:
: TIA,
: Kani
:
[blue]The name of the array = address of the first element of that array. Try that with just the variable:
: [code]
: int i = 5;
:
: printf("%08X, %08X
", &i, i);
: [/code]
[/blue]
• : Hi,
:
: The following code,
:
: [code]
: unsigned long x[4], y[4];
:
: printf("Values with & operator - %08X, %08X
", &x, &y);
: printf("Values without & operator - %08X, %08X
", x, y);
: [/code]
:
: prints the output,
:
: Values with & operator - 0012FEC8, 0012FEB0
: Values without & operator - 0012FEC8, 0012FEB0
:
: Now my question is, shouldn't values of x and [b]&[/b]x be different?
:
: TIA,
: Kani
:

y is the address of the first element in the array.
&y is the address of the array itself - an array pointer.

Array pointers are rather uncommon and not something you need to know about in detail as a beginner. Their most common usage is function parameters:

void func (int array[10]);

When you pass an array to that function, you will be passing an array pointer. Only the pointer is allocated and not a whole array. Yep, the syntax is very confusing since it looks like you are declaring an array. But the above is an exception: when writing "int array[10]" as a parameter to a function, you will get an array pointer. Writing it elsewhere will give you an array.

• : : Hi,
: :
: : The following code,
: :
: : [code]
: : unsigned long x[4], y[4];
: :
: : printf("Values with & operator - %08X, %08X
", &x, &y);
: : printf("Values without & operator - %08X, %08X
", x, y);
: : [/code]
: :
: : prints the output,
: :
: : Values with & operator - 0012FEC8, 0012FEB0
: : Values without & operator - 0012FEC8, 0012FEB0
: :
: : Now my question is, shouldn't values of x and [b]&[/b]x be different?
: :
: : TIA,
: : Kani
: :
: [blue]The name of the array = address of the first element of that array. Try that with just the variable:
: : [code]
: : int i = 5;
: :
: : printf("%08X, %08X
", &i, i);
: : [/code]
: [/blue]
:

"The name of the array = address of the first element of that array."
But that would mean x = &x[0] and not x = &x. Please correct me if I am wrong.
• : : : Hi,
: : :
: : : The following code,
: : :
: : : [code]
: : : unsigned long x[4], y[4];
: : :
: : : printf("Values with & operator - %08X, %08X
", &x, &y);
: : : printf("Values without & operator - %08X, %08X
", x, y);
: : : [/code]
: : :
: : : prints the output,
: : :
: : : Values with & operator - 0012FEC8, 0012FEB0
: : : Values without & operator - 0012FEC8, 0012FEB0
: : :
: : : Now my question is, shouldn't values of x and [b]&[/b]x be different?
: : :
: : : TIA,
: : : Kani
: : :
: : [blue]The name of the array = address of the first element of that array. Try that with just the variable:
: : : [code]
: : : int i = 5;
: : :
: : : printf("%08X, %08X
", &i, i);
: : : [/code]
: : [/blue]
: :
:
: "The name of the array = address of the first element of that array."
: But that would mean x = &x[0] and not x = &x. Please correct me if I am wrong.
:

You are correct. See my post for details.