C pointer : array variable

后端 未结 7 500
盖世英雄少女心
盖世英雄少女心 2021-01-20 18:09

I read this in my book (and many sources on the internet):

The array variable points to the first element in the array.

7条回答
  •  执笔经年
    2021-01-20 18:45

    When you use an array expression, the compiler converts it to a pointer to the first element. This is an explicit conversion specified by the 1999 C standard, in 6.3.2.1 3. It is a convenience for you, so that you do not have to write &array[0] to get a pointer to the first element.

    The conversion happens in all expressions except when an array expression is the operand of sizeof or the unary & or is a string literal used to initialize an array.

    You can see that an array and its first element are different by printing sizeof array and sizeof array[0].

提交回复
热议问题