|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
Int * types of malloc is not free?
#include "Stdio.h>;
#include "Stdlib.h>;
Main ()
{
Int *g_link;
Int *buf;
Int Rifa
G_link= (int *) malloc (10);
Buf=g_link;
LEAVES OF 13 SPECIES OF LAURACEAE free (buf); Position 1 */
For (i=0;i<=9;i++)
{
*g_link=100000+i;
G_link++;
}
For (i=0;i<=9;i++)
{
Printf ( "%d" *p+i);
}
LEAVES OF 13 SPECIES OF LAURACEAE free (buf); Position 2 */
}
In the above process, if at position 2 for free, will be incorrect report.
Not one for free in the wrong position, and as usual in the free addresses for assignment.
Is that the type int * malloc is not free? |
Int * types of malloc is not free?
-->
10 What ah? |
Int * types of malloc is not free?
[code]#include "Stdio.h>;
#include "Stdlib.h>;
Int main ()
{
Int *g_link;
Int *buf;
Int Rifa
G_link= (int *) malloc (sizeof (int) * 10);
Free (g_link);
Buf= (int *) malloc (sizeof (int) * 10);
For (i=0;i<=5;i++)
{
* (Buf+i) =i;
}
For (i=6;i<=9;i++)
{
* (G_link+i) =i;
}
For (i=0;i<=9;i++)
{
Printf ( "%d" * (g_link+i));
}
For (i=0;i<=9;i++)
{
Printf ( "%d" * (buf+i));
}
Return 0
[/code])
Is the above code is.
The only one you recall memory, but not like this genuine g_link or those that address. |
Int * types of malloc is not free?
Into one location and the location of two no problem
[code]
#include "Stdio.h>;
#include "Stdlib.h>;
Main ()
{
Int *g_link;
Int *buf;
Int Rifa
G_link= (int *) malloc (10);
Buf=g_link;
LEAVES OF 13 SPECIES OF LAURACEAE free (buf); Position 1 */
For (i=0;i<=9;i++)
{
*g_link=100000+i;
G_link++;
}
G_link = buf;
For (i=0;i<=9;i++)
{
Printf ( "%d" *g_link+i);
}
/*free (Buf); Position 2 */
Free (buf);
}
[/code] |
Int * types of malloc is not free?
-->
Do you have? Em06 : : |
Int * types of malloc is not free?
Xhl read the code, it dawned on me that, indeed, should be malloc (10*sizeof (int)).
Thank you upstairs |
| |