Re: [Dev-C++] warning when deleting allocated mem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Luigi S. <gi...@li...> - 2001-12-20 23:51:52
|
I agree with what Mr. Woods says about the reason why you are getting the
warning.
Here, I would like to point out what IMHO is another problem.
In your code you say:
...
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
pArray[i][j] = new char [10]; // acquire space for 10 characters
strcpy(pArray[0][0],"1234567890"); // copy 10 + 1 characters in pArray[0][0]
...
remember that "1234567890" is a string literal made of 10 + 1 characters
(the "+1" is for the terminating '\0'); thus your code writes beyond the
end of the array pArray[0][0].
At 18.08 18/12/01 -0800, Julio Lajara wrote:
>I can't figure out why the compiler gives me a warning
>about deleting the array in the following code:
>
>...
--
gisan
gi...@li...
|