Home » C Programming » Structures » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    typedef struct p *q;
    int main()
    {
    struct p
    {
    int num1;
    char num2;
    q ptr;
    };
    struct p p = {50, 55, &p};
    printf("%d\n", p.ptr->x);
    return 0;
    }
    1. 50
    2. 55
    3. Compilation Error
    4. Garbage value
    5. None of these
Correct Option: C

Compilation Error

main.c: In function ‘main’:
main.c:11:29: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
struct p p = {1, 2, &p};
^
main.c:11:29: note: (near initialization for ‘p.ptr’)
main.c:12:29: error: dereferencing pointer to incomplete type ‘struct p’
printf("%d\n", p.ptr->x);
^~



Your comments will be displayed only after manual approval.