Home » C Programming » Storage Classes » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    struct p
    {
    struct p *next;
    int n;
    };
    int main()
    {
    struct p* ptr1 = malloc(sizeof(struct p));
    ptr1->n = 1;
    ptr1->next = malloc(sizeof(struct p));
    printf("%d\n", ptr1->next->n);
    return 0;
    }
    1. Garbage value
    2. 1
    3. 0
    4. Compilation error
    5. None of these
Correct Option: A

Garbage value



Your comments will be displayed only after manual approval.