Example for memory allocation in c:
What is the output of below c program?
int *p = malloc(sizeof(int));
*p = 100;
100, garbage value
100, and garbage or crash.
*p will print 100 first and " *p++ " --> this statement, increments the p to point to next integer available and fetches that value. Since p is not pointing to an array, so incrementing p may point to some unknown next location, on accessing it, either it may print some garbage or may crash.
Back To Top