c++ - Deleting a pointer to an automatic variable -


this question has answer here:

please @ code

int = 10;                                     //line 1  int *p = &i;                                    //line 2   delete p;                                       //line 3  cout << "*p = " << *p << ", = " << << endl; //line 4   = 20;                                         //line 5   cout << "*p = " << *p << ", = " << << endl; //line 6   *p = 30;                                        //line 7 cout << "*p = " << *p << ", = " << << endl; //line 8   

what result of code? of line 3, 5 , 7? invoke undefined behavior? output?

edit : tried running using g++, , it's compiling , running fine! i'm using mingw on windows 7.

what standard in context?

you can delete pointer if have ever allocated dynamically using new. in case have not allocated pointer using new defined , initialized point local variable of type int.

invoking delete on pointer not allocated dynamically using new called undefined behavior. in short, means on earth can happen when such code executed , can't complaint bit on planet.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -