Multiple choice technology programming languages

The following statement would allocate memory on? char *ptr = malloc(10);

  1. Stack

  2. Heap

  3. Code Segment

  4. Data Segment

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

In C, the malloc() function allocates memory dynamically on the heap. The statement 'char *ptr = malloc(10);' allocates 10 bytes on the heap and stores the address in pointer ptr (which itself is on the stack). The stack is used for local variables, code segment for instructions, and data segment for static/global variables.