when allocating memory, it is recommended to manually check whether the allocation was successful (or more accurately, terminate the program if it wasn't).
Main:
int main (void)
{
char *c = malloc(/*amount of memory to allocate*/);
if (c == NULL) {
printf("optional error message");
return 1;
}
}
Any return value != 0, in the main function signals an error. Whatever return (error) value is given is arbitrary?
Void
void allocate()
{
char *c = malloc(/*amount of memory to allocate*/);
if (c == NULL) {
printf("optional error message");
return;
}
}
Will the function not exit without an error (ie except for the printed error message, the program will still run like the function ran successfully)?
Non void
int allocate()
{
char *c = malloc(/*amount of memory to allocate*/);
if (c == NULL) {
printf("optional error message");
return 1;
}
}
Will the function not exit without an error and return 1?