[Courses] Re: pointers, array's, and sizeof()

Xp0nential Xp0nential Xp0nential at root-core.com
Sun Feb 3 14:06:20 EST 2002


Ok I just realised that there are two rules.
one that pertains to expressions and the other one which I was talking about only pertains to formal parameters of functions.
they are at different levels.


>>        int a[5] = {1, 2, 3, 4, '\0'};
>>	cout << a << endl;
>>        cout << *a << endl;
>>
>>run the above code:
>>
>>	# ./a.out
>>	0xbffff788
>>	1
>>

same rules apply to C++.

"An lvalue of type array-of-T which appears in an expression decays (with three exceptions) into a pointer to its first element; the type of the resultant pointer is pointer-to-T.

(The exceptions are when the array is the operand of a sizeof or & operator, or is a string literal initializer for a character array.)"

In this case cout << a ; this rule does apply. and a decays to a pointer  to its first element.
the only issue is this statement "arrays are pointer to their first element" in general is just not totally accurate cause there are exceptions.
This seems to be a "don't mess with it" subjects to theoerists :P.
Its just a theory issue has nothing to do with writing code that much..

so ignoreeeeeeeeeeeee 
regards
Xp0nential


_____________________________________________________________
[Root-Core Network] - [www.root-core.org] - Free E-mail



More information about the Courses mailing list