Reputation: 13
Windows has triggered a breakpoint in myprogram.exe
.
This may be due to a corruption of the heap, which indicates a bug in myprogram.exe
or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while projtest.exe
has focus.
The output window may have more diagnostic information.
Working code:
void main()
{
const unsigned char a_size = 15;
int *a = new int[a_size];
memset(a,0,a_size*sizeof(a));
delete [] a;
}
Error code:
void main()
{
const unsigned char a_size = 15;
char *a = new char[a_size];
memset(a,0,a_size*sizeof(a));
>delete [] a;
}
'>'
is breakpoint position.
So, char type in dynamic arrays causing errors.
Additional Info : Using Visual Studio C++ 2008
Upvotes: 1
Views: 6976
Reputation: 87201
A star is missing within sizeof:
memset(a,0,a_size*sizeof(*a));
That's because:
sizeof(a) == sizeof(int*) -- usually 4 or 8
sizeof(*a) == sizeof(int) -- usually 4
Upvotes: 1