Runtime error in the following code

后端 未结 4 2103
北恋
北恋 2021-01-26 10:13

The following code,according to me should run successfully,but fails at runtime.I don\'t get the reason:

 void main()
 {
   int arr[5][3]={1,2,3,4,5,6,7,8,9,10,1         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-26 10:54

    With the line

    int **p=&m
    

    you create a pointer to a pointer to an integer.

    Then, you add one to the address - one memory address, that is, not one times the number of bytes to point to the next integer.

    Then you deference it twice:

    • both dereferences will return unspecified values, so the second dereference may break memory boundaries for the OS you are using,
    • both times it will be off boundary alignmemnt, which may cause issues in some OSes.

提交回复
热议问题