Home » C Programming » Functions » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    struct NN
    {
    char *name;
    struct NN *next;
    };
    struct NN *ptrary[10];
    struct NN n, nn;
    n.name = "Rahul";
    n.next = NULL;
    ptrary[0] = &n;
    nn.name = (char*)malloc(sizeof(char)*3);
    strcpy(nn.name, n.name);
    nn.next = &nn;
    ptrary[1] = &nn;
    printf("%s\n", ptrary[1]->next->next->name);
    }
    1. Rahul
    2. Garbage value
    3. Compilation Error
    4. Undefined behaviour
    5. None of these
Correct Option: A

Rahul



Your comments will be displayed only after manual approval.