Why is arr and &arr the same?

前端 未结 6 733
鱼传尺愫
鱼传尺愫 2020-12-07 21:12

I have been programming c/c++ for many years, but todays accidental discovery made me somewhat curious... Why does both outputs produce the same result in the code below? (<

6条回答
  •  一向
    一向 (楼主)
    2020-12-07 21:59

    The address is the same but both expressions are different. They just start at the same memory location. The types of both expressions are different.

    The value of arr is of type int * and the value of &arr is of type int (*)[3].

    & is the address operator and the address of an object is a pointer to that object. The pointer to an object of type int [3] is of type int (*)[3]

提交回复
热议问题