Initialization from incompatible pointer type warning when assigning to a pointer

后端 未结 5 539
梦谈多话
梦谈多话 2020-12-06 16:46

GCC gives me an \'Initialization from incompatible pointer type\' warning when I use this code (though the code works fine and does what it\'s supposed to do, which is print

5条回答
  •  余生分开走
    2020-12-06 17:08

    The output is the same because the address of arr[0] is literally equivalent to the pointer to arr[]. Any pointer initialized to point to arr[0] will have as its value the address of arr[0]; that's what a pointer is. Read up on pointer and especially on their relationship to arrays. The are countless tutorials out there, some of which probably show your two cases as examples.

提交回复
热议问题