malloc() function callstatic keyword. The heap holds memory that the programmer explicitly requests at run time using functions like malloc(), calloc(), or realloc(), and this memory persists until it is explicitly freed with free(), not tied to any single function call. static keyword makes this variable retain its value across calls and gives it a fixed memory location for the whole program's lifetime, exactly like a global variable, so it is stored in the static/data segment, not the heap. static or dynamic allocation is a local (automatic) variable. Its size is fixed at compile time, and its memory is automatically allocated when the function is entered and automatically released when the function returns, exactly the behavior of the stack, not the heap. malloc(). malloc() is to request memory from the heap at run time. This memory is not tied to the function that called malloc(), it survives even after that function returns, and it remains allocated until the program explicitly calls free() on it (or the program ends). This is the defining characteristic of heap memory, so option (C) is exactly the case that is stored in the heap. malloc() is, by definition, heap memory. Consider the following code:
main() {
int x = 126, y = 105;
{
if (x > y)
x = x - y;
else
y = y - x;
}
while (x != y)
printf("%d", x);
}
Consider the following code:
int a;
int arr[] = {30, 50, 10};
int *ptr = arr[10] + 1;
a = *ptr;
(*ptr)++;
ptr = ptr + 1;
printf("%d", a + arr[1] + *ptr);