Runtime error in the following code

后端 未结 4 2097
北恋
北恋 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:50

    int **p=&m;
    

    p points to address, where m is placed:

    ... |  m  | sth | ... |  p  | ...
           ^                 V
           |_________________|
    

    Now, increment it:

    ... |  m  | sth | ... |  p  | ...
                 ^           V
                 |___________|
    

    So, now p points to sth. What is sth? Nobody knows. But you're trying to get access to the address sth contains. This is undefined behavior.

提交回复
热议问题