Semantics of char a[]

后端 未结 6 620
忘掉有多难
忘掉有多难 2021-02-01 23:34

I recently embarrassed myself while explaining to a colleague why

char a[100];
scanf(\"%s\", &a); // notice a & in front of \'a\'

is ve

6条回答
  •  情歌与酒
    2021-02-02 00:16

    char [100] is a complex type of 100 adjacent char's, whose sizeof equals to 100.

    Being casted to a pointer ((void*) a), this variable yields the address of the first char.

    Reference to the variable of this type (&a) yields address of the whole variable, which, in turn, also happens to be the address of the first char

提交回复
热议问题