Home » C Programming » Structures » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    struct option1
    {
    int m;
    int n;
    };
    struct option2
    {
    int m;
    int n;
    };
    struct option1 fun();
    int main()
    {
    struct option1 opt1 = {11};
    struct option2 opt2 = {21, 31};
    opt2 = fun();
    printf("%d\n", opt2.m);
    }
    struct option1 fun()
    {
    struct option1 temp = {11, 21};
    return temp;
    }
    1. 21
    2. 11
    3. Compilation Error
    4. Undefined behaviour
    5. None of these
Correct Option: C

Compilation Error

main.c: In function ‘main’:
main.c:17:14: error: incompatible types when assigning to type ‘struct option2’ from type ‘struct option1’
opt2 = fun();



Your comments will be displayed only after manual approval.