Pointer arithmetic in c and array bounds

后端 未结 3 789
鱼传尺愫
鱼传尺愫 2020-12-20 19:08

I was browsing through a webpage which had some c FAQ\'s, I found this statement made.

Similarly, if a has 10 elements and ip points to a[3],

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 20:08

    The behaviour would be undefined in the following case

    int a[3];
    (a + 10) ; // this is UB too as you are computing &a[10]
    *(a+10) = 10; // Ewwww!!!!
    

提交回复
热议问题