Pointer vs array in C, non-trivial difference

后端 未结 4 1378
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 21:30

I thought I really understood this, and re-reading the standard (ISO 9899:1990) just confirms my obviously wrong understanding, so now I ask here.

The following prog

4条回答
  •  Happy的楠姐
    2020-11-27 22:11

    An array is a kind of storage. Syntactically, it's used as a pointer, but physically, there's no "pointer" variable in that struct — just the three ints. On the other hand, the int pointer is an actual datatype stored in the struct. Therefore, when you perform the cast, you are probably* making ptr take on the value of the first element in the array, namely 1.

    *I'm not sure this is actually defined behavior, but that's how it will work on most common systems at least.

提交回复
热议问题