-
What will be the output of the following C code?
#include <stdio.h>
struct p
{
int x;
char y;
};
void foo(struct p* );
int main()
{
typedef struct p* q;
struct p p1[] = {15, 52, 43, 34, 25, 16};
foo(p1);
}
void foo(struct p* p1)
{
q ptr1 = p1;
printf("%d\n", ptr1->x);
}
-
- Undefined behaviour
- 15
- Compilation Error
- Segmentation fault
- None of these
Correct Option: C
Compilation Error
main.c: In function ‘foo’:
main.c:16:9: error: unknown type name ‘q’
q ptr1 = p1;
^
main.c:16:18: warning: initialization makes integer from pointer without a cast [-Wint-conversion]
q ptr1 = p1;
^~
main.c:17:28: error: invalid type argument of ‘->’ (have ‘int’)
printf("%d\n", ptr1->x);