-
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;
}
-
- 50
- 55
- Compilation Error
- Garbage value
- 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);
^~