C/C++ changing the value of a const

后端 未结 18 1836
醉梦人生
醉梦人生 2020-11-28 07:28

I had an article, but I lost it. It showed and described a couple of C/C++ tricks that people should be careful. One of them interested me but now that I am trying to repli

18条回答
  •  星月不相逢
    2020-11-28 07:43

    #include
    int main( void )
    {
       int i = 3;    
       const int *pi = &i;
       int *pj = (int*)&i;
        *pj = 4;
    
       getchar(); 
       return 0;  
    }
    

提交回复
热议问题