My char pointer points to invalid value after being cast from int*

前端 未结 7 658
余生分开走
余生分开走 2021-02-03 17:19

I am learning C programming language, I have just started learning arrays with pointers. I have problem in this question, I hope the that output must be

7条回答
  •  醉梦人生
    2021-02-03 18:12

    It's because the size of char is one, and the size of int is four. This means that adding 4 to ptr makes the result point to the second entry in the int array.

    If you compiled this on a big endian system you would have printed 33554432 instead.

提交回复
热议问题