I'm learning C and I'm wondering what is the point of sizeof(char) *100
in
char *temp = (char*) malloc(sizeof(char) * 100);
I understand the sizeof(char) to be 1, so why we can't just write malloc(100)
?
Thanks
I'm learning C and I'm wondering what is the point of sizeof(char) *100
in
char *temp = (char*) malloc(sizeof(char) * 100);
I understand the sizeof(char) to be 1, so why we can't just write malloc(100)
?
Thanks
There's no point to using sizeof(char)
in this case.
The C standard defines sizeof(char)
to be 1, so better to just use malloc(100)
.