July 13th, 2003, 01:12 PM
another malloc question
if I do this
char * p = (char*) malloc(sizeof(char) * 30);
p = '\0';
How much memory did I free? was it the whole 30 bytes that I putted asside with the first statement, or just 21bytes caused by putting a binary 0 at offset 20?
and if it is only 21 bytes, did i just created a memory leak?
Some day I'll create a smart quote to put here.
July 13th, 2003, 01:58 PM
July 14th, 2003, 07:52 AM
yes it frees 30 bytes of memory
'\0' is not a specifier for end memory location
it is only a value stored at memory location
it is use a specifier in C for end of string like $ symbol use in Assembly
July 14th, 2003, 01:11 PM
thanks guys, specialy for the clarifing explanation.