LogiQuest
Back to Memory Allocation
1

What will be the output of the program?

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int *p = malloc(3 * sizeof(int));
    if (!p) return 1;
    p[0] = 1; p[1] = 2; p[2] = 3;
    printf("%d\n", p[0] + p[1] + p[2]);
    free(p);
    return 0;
}
Easy

Discussion (0)

  • No discussion yet. Ask a doubt or share a shortcut.

Log in to join the discussion.