gives the same base address of array?
how is this possible?
how arr and &arr can give the same address?
Well, &arr is the address of the array and arr is the address of its first
element. The two expressions have the same value but different type.
Printing pointer values with %u is undefined.
--
Joe Wright
"If you rob Peter to pay Paul you can depend on the support of Paul."
Yes, but more precisely, arr is an expression of array type that
refers to value of the the array object. But an expression of array
type, in most contexts, is implicitly converted to a pointer to the
array's first element.
> The two expressions have the same value but different
> type.
Right.
> Printing pointer values with %u is undefined.
Right.
This:
int arr[10];
printf("%p %p\n", (void*)&arr, (void*)arr);
will almost certainly print the same value twice.
--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Why "almost"? I cannot see any reason for "almost". I believe it
*must* print the same value twice.
What is the basis of your belief?
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
Well, I was sure there was something about type compatibility. But now
that I've examined the standard, I see I'm wrong.
>Why "almost"? I cannot see any reason for "almost". I believe it
>*must* print the same value twice.
Is it even true that
int x;
printf("%p %p\n", (void*)&x, (void*)&x);
must print the same value twice? As a trivial example, it could
print "0x0000123a" and "0x0000123A"; on a system with segmented
addresses it could print "0012:003a" and "0010:023a'.
-- Richard
--
Please remember to mention me / in tapes you leave behind.
Well, this option is formally acceptable, too, though printing two
different strings for the same representation seems sort of
schizophrenic to me. :-)
... or making two different representations for the same pointer
value ...
it doesnt make much sense for it to print two different strings...ok
well, maybe its just me and my system (cos it prints the same value
twice!)
>On Feb 16, 4:34 pm, achp <achp...@gmail.com> wrote:
>> On 16 ???, 18:33, achp <achp...@gmail.com> wrote:
>>
>> > printing two
>> > different strings for the same representation
>>
>> ... or making two different representations for the same pointer
>> value ...
>>
>> > seems sort of
>> > schizophrenic to me. :-)
>
>it doesnt make much sense for it to print two different strings...ok
>well, maybe its just me and my system (cos it prints the same value
>twice!)
There is a difference between what happens on most (or even all)
current implementations and what the standard requires to happen. In
this case, the standard does not require the two outputs to be the
same. It's not that you (and I) can't see any reason for it to print
two different strings, it's that there is no reason in the standard
that it cannot.
There is also a difference between the limits of one's experience and
imagination and the real world. There are people who fervently
believe '0'-0x30 == 0, 'i'+1 == 'j', or an implementation of strlen or
strcpy requires the source code to have a loop looking at each
character in turn. (None of these are true on my system.) The fact
that I don't know of an implementation where sizeof(int) == 7 or
CHAR_BITS == 11 is irrelevant as far as the standard is concerned.
--
Remove del for email