Examveda

What will be the output of the following C code?
#include <stdio.h>
struct p
{
    int x[2];
};
struct q
{
    int *x;
};
int main()
{
    struct p p1 = {1, 2};
    struct q *ptr1 = (struct q*)&p1;
    ptr1->x = (struct q*)&p1.x;
    printf("%d\n", ptr1->x[0]);
}

A. Compile time error

B. Undefined behaviour

C. Segmentation fault/code crash

D. 1

Answer: Option B


This Question Belongs to C Program >> Structure And Union

Join The Discussion

Related Questions on Structure and Union