The answer is correct because it accurately captures the fundamental distinction between these two memory allocation functions in C. malloc() allocates a block of uninitialized memory and requires only the total number of bytes as a single argument, while calloc() allocates memory for an array of elements, takes two arguments (number of elements and size per element), and crucially initializes all allocated memory to zero. This initialization feature of calloc() is a key advantage when you need guaranteed zero values, whereas malloc() leaves memory with whatever garbage values were previously there. Other options would be incorrect if they claimed malloc() initializes memory, if they stated calloc() takes only one argument, or if they reversed which function initializes to zero.
A Stack follows LIFO principle where the last element inserted is the first one to be removed.
It is fundamental in managing function calls through the call stack, undo/redo operations, and expression evaluation.
Queues use FIFO, Heaps are used for priority ordering, and Linked Lists maintain sequential but flexible storage.
int x = 5;
printf("%d", x++);
The post-increment operator (x++) returns the current value of x before incrementing. So printf prints 5, and then x becomes 6.
In C, pointers are declared using the asterisk (*) symbol before the variable name. The syntax is 'datatype *pointer_name;'
char arr[10];
Each char occupies 1 byte in memory. An array of 10 chars will occupy 10 × 1 = 10 bytes.
void is used in two contexts: (1) as a function return type when a function doesn't return a value, and (2) to declare a generic pointer (void *) that can point to any data type.
int a = 10, b = 20;
int c = (a > b) ? a : b;
printf("%d", c);
The ternary operator (condition ? true_value : false_value) evaluates the condition (a > b). Since 10 is not greater than 20, it returns b which is 20.
strlen() returns the length of a string without counting the null terminator ('\0'). For example, strlen("hello") returns 5, not 6.
The stdio.h header file contains declarations for standard input/output functions like printf() and scanf().
Variable names in C must start with a letter or underscore, not a digit. _variable is valid. '2var' starts with digit, 'var-name' contains hyphen (invalid), 'var name' contains space (invalid).