Multiple choice technology programming languages

What is the scope of memory allocated with malloc function?

  1. Local to the file in which its allocated.

  2. Local to the function in which its allocated.

  3. Local to the block in which its allocated.

  4. Global

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Memory allocated by malloc() has global scope - it persists until explicitly freed with free() or program termination, regardless of which function or block allocated it. The allocated memory can be accessed from anywhere in the program via its pointer. Options A, B, and C incorrectly restrict the scope to file, function, or block level.