Global integer array with No dimension

前端 未结 2 411
陌清茗
陌清茗 2020-12-19 09:30

What is the concept when we define a global array with no dimension This shows output as 16.

    #include 
    #include 
    i         


        
2条回答
  •  再見小時候
    2020-12-19 10:25

    GCC assumes that arr should only have one element. The fact that you can access other elements than arr[0] without segfaulting is just a coincidence. For instance, on my machine I can access arr[1], arr[10] and arr[100] just fine, but arr[1000] causes a segfault. In general, accessing locations outside array bounds causes undefined behavior.

提交回复
热议问题