C pointer : array variable

后端 未结 7 497
盖世英雄少女心
盖世英雄少女心 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 19:04

    Look at it this way:

    &msg = 0x0012
    &msg[0] = 0x0012
    &msg[1] = 0x0013
    

    In this case &msg[1] is pointing to msg+1. When you reference &msg or &msg[0] you are referring to the same address of memory because this is where the pointer starts. Incrementing the array variable will increment the pointer by +1 since a char variable is only 1 byte in size.

    If you do the same trick with say an integer you will increment the pointer by +4 bytes since an integer is 4 bytes in size.

提交回复
热议问题