Home > Back-end >  Triggered when the delete function in the implementation of the breakpoint
Triggered when the delete function in the implementation of the breakpoint

Time:12-09

Using vscode
Execute the following code
 
Int main ()
{
Char * b="Hello";
Char * a=new char;
Strcpy (a, b);
Cout & lt; Delete a;
Cout & lt; system("pause");
}

In the execution to delete a; When the abnormal vscode pop-up
 
Abnormal,
Trace/breakpoint trap

Want to ask is why?

CodePudding user response:

Delete a; Behind that a cout & lt; CodePudding user response:

The problem inside the
1. Didn't specify the new size
2. Delete an object, the redistribution before, can't operate the object

CodePudding user response:

 
Int main ()
{
Char * b="Hello";
Char * a=new char;//here into a char * a=new char [6].
Strcpy (a, b);
Cout & lt; Delete a;//the last side, otherwise destroyed you also how to do, and want to delete []
system("pause");
}

CodePudding user response:

You this is India program,

New char application 1 byte space,
Then try to use the space of one byte of the 6 bytes,

May only have three elder brother on the other side of the compiler can have a try,
  • Related