Jack said:
char *p;
p = (char*)malloc(10 * sizeof(char)); //LINE1
This is not the best way to call malloc().
First, if you have a proper prototype in scope, the cast does nothing.
OTOH, if you do not have a proper prototype in scope, the cast is likely
to hide any error messages your compiler might have given you to warn
you of this mistake, and the result is likely to be garbage. Lose the
cast.
Second, sizeof(char) is always 1. This is guaranteed by the Standard. If
you know that p is always going to be a char * (i.e., it holds a
string), you can omit the sizeof(char).
OTOH, if you do _not_ know that p is always going to be a char * (e.g.,
it holds flags, and it may some day become a struct flags * instead),
then it should be treated as a normal malloc() call. Any normal malloc()
call is easier to maintain properly if you do not ask for N*sizeof(type)
but for N*sizeof *pointer. When the type of the pointer changes,
N*sizeof(type) may be incorrect and need changing; but N*sizeof *pointer
is always right no matter what type pointer has.
Also, double spacing is an abomination concocted by a conspiracy of
typewriter makers and stationers. Also also, magic numbers are to be
abhorred.
All in all, your code is better this way:
#define MAX_LENGTH 10
char *p;
p = malloc(MAX_LENGTH * sizeof *p);
After LINE1, the 10 char-length memory that p points to is empty or
some random characters?
The latter.
Richard