Richard Heathfield said:
Sourcerer said:
No.
a is a pointer to an address where the array a[] begins.
Strictly, it is an array that, when evaluated, yields as its value the
address of its first element.
OK, that means that evaluated a = &a. &a is then the address of the array which
The do point to the same address. However, since they are of
different and incompatible types, equality has little meaning.
Furthermore, assigning each expression to a pointer of the appropriate
type could result in different bit patterns. The standard does not
require the two pointers to use the same representation or to even be
of the same size.
I earlier considered 'a' to be.
Only I have not been consistent in another matter earlier. &a isn't a pointer
(see example below). It is the value directly encoded into the binary processor
commands.
&a isn't a pointer simply because it is not an object. It is an
expression which can be evaluated. The expression does have **type**
pointer to array N of int.
snip
Hmm... interesting how this subtlety affects program execution. Consider the
following program:
#include <stdio.h>
int main(void){
int a[5];
printf("%d, %d\n", sizeof(a), sizeof(&a));
sizeof returns a size_t which need not be a flavor of int. If you
want to use %d, cast the result.
return 0;
}
I first assumed this should give the output (if sizeof(int) = 4):
20, 4
If sizeof(int) is 4, the 20 is reasonable. Why do you think the
sizeof(int(*)[5]) should be 4? The two are not related.
This would be true if &a was a pointer, but it isn't. Execution of this program
gives the output:
20, 20
This only proves your compiler is broken or maybe sizeof(int(*)[5]) is
actually 20. I'm using VC 6 and, after adding the casts, mine
produces the same erroneous result. However, adding
int (*b)[5];
b = &a;
printf("%d, %d\n", (int)sizeof(a), (int)sizeof(b));
before the first printf produces the expected result of 20, 4.
Since we know a is not evaluated when the operand of the & operator,
the sizeof(&a) and the sizeof(b) must be the same.
Why is the second value 20 as well? What exactly is
sizeof(&anything_that_is_not_a_pointer)?
For any type T and an object t of that type, sizeof(&t) must be the
same as sizeof(T*).
Remove del for email