anonymous wrote:
> Anand wrote:
>> anonymous wrote:
>>> I have couple of questions related to array addresses. As they belong
>>> to the same block, I
>>> am putting them here in one single post. I hope nobody minds:
>>>
>>> char array[35];
>>>
>>> int address;
>>>
>>> Questions 1:
>>> Why cannot I do the following:
>>>
>>> address = (int)array;
>>>
>>> whereas I found it perfectly alright to do the following:
>>>
>>> address = (int)&array;
>>>
>>> Question 2:
>>> What is the difference between array and &array. Are not they the same
>>> thing i.e. starting
>>> address of the array.
<snip>
>> Q2: Both means the same i.e. address of the first element.
>> [ However the moment you pass an array to a function, the meaning
>> changes, and hence meaning of array and &array differs there ]
>
> Can you be more elaborate on this please?
It's not quite right. &array is always different from array, they differ
in type. So, given your definition above, the compiler *must* complain
if you pass &array to a function with a prototype in scope specifying a
pointer to char. E.g.
#include <string.h>
int main(void)
{
char array[35] = "hello";
size_t len1 = strlen(array); /* this is allowed */
size_t len2 = strlen(&array); /* The compiler is required to complain */
}
&array has type pointer to array, where as array otherwise degenerates
to a pointer to char.
>> Q3&Q4: array is not an lvalue, see section:
>> 6.3.2.1 Lvalues, arrays, and function designators
>> So you cannot modify it.
>> ( Again the meaning of array changes the moment you pass it to
>> function)
>>
>> --
>> (Welcome) http://www.ungerhu.com/jxh/clc.welcome.txt
>> (clc FAQ) http://www.eskimo.com/~scs/C-faq/top.html
>
> Can I get a copy of the standard for download from somewhere?
Google for n1124 and you will find the draft for C99 + all the
subsequent corrections. That and all the other publicly available copies
are at
http://www.open-std.org/jtc1/sc22/wg14/www/docs/ or you can buy a
copy of the actual release version.
I think though that you really need to work through a good text book
though, such as K&R2, and also read the FAQ (the URL is above) which
will tell you what K&R2 is (in the Bibliography, I think).
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.