When using malloc and doing similar memory manipulation can I rely on sizeof( char ) being always 1?
For example I need to allocate memory for N elements of type char. Is ...
I'm a total C newbie, I come from C#. I've been learning about memory management and the malloc() function. I've also came across this code:
char *a_persons_name = malloc(sizeof(char) + 2);
When answering a comment to another answer of mine here, I found what I think may be a hole in the C standard (c1x, I haven't checked the earlier ones ...
The following C program:
printf("%u %u %u\n",sizeof "",sizeof(""+0),sizeof(char *));
I was doing some C coding and after reading some C code I've noticed that there are code snippets like
char *foo = (char *)malloc(sizeof(char) * someDynamicAmount);