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

Compilation Error

main.c: In function ‘main’:
main.c:11:10: error: invalid type argument of ‘->’ (have ‘struct B’)
b->name = "Raj";
^~
main.c:12:10: error: invalid type argument of ‘->’ (have ‘struct B’)
b->next = NULL;
^~
main.c:14:25: error: invalid type argument of ‘->’ (have ‘struct B’)
printf("%s\n", b->name);



Your comments will be displayed only after manual approval.