Re: array questions



On Fri, 17 Jun 2005 23:55:58 +0200, Martijn wrote:

>>> char arr[10];
>>>
>>> When we find sizeof(arr) ---> Output is 10, arr is treated as
>>> an object of 10 chars.
>>>
>>> When we say arr+1, ---> arr is treated as a pointer to char.
>>>
>>> Why is this anomalous behaviour ?
>>
>> arr is the address of the first element, arr[0]. arr + 1 is address
>> of second element, arr[1], and so on. What is anomalous about this?
>
> A lot of people forget that sizeof is not a function call, more like an
> operator.

It is precisely an operator.

Lawrence
.



Relevant Pages

  • Re: array questions
    ... > Consider an array. ... > an object of 10 chars. ... > Why is this anomalous behaviour? ... Prev by Date: ...
    (comp.lang.c)
  • Re: malloc
    ... sizeof is only slightly better. ... If you, say, switch to ... wide chars other changes are also needed ... Prev by Date: ...
    (comp.lang.c)
  • Re: array questions
    ... >> an object of 10 chars. ... >> Why is this anomalous behaviour? ... > of second element, arr, and so on. ... pointer, hence the result will be the size of a pointer to a char, which is ...
    (comp.lang.c)
  • Re: bytes calculation
    ... Please, are you a lawyer? ... sizeof returns the number of chars in an object ... Nick Keighley ...
    (comp.lang.c)
  • Re: read and write
    ... Is there a way to pass something like sizeof to that last write ... parameter to not have to put an exact number of bytes in it? ... This an actual array of chars, not a pointer to an array of ... chars located elsewhere. ...
    (comp.unix.programmer)