Structures


  1. What will be the output of the following C code?
    #include <stdio.h>
    struct MansWear
    {
    int size1;
    int size2;
    };
    struct WomensWear
    {
    int size1;
    int size2;
    };
    void fun(struct MansWear);
    int main()
    {
    struct WomensWear WW = {39, 42};
    fun(WW);
    }
    void fun(struct MansWear MW)
    {
    printf("%d\n", MW.size1);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Compilation Error

    main.c: In function ‘main’:
    main.c:16:13: error: incompatible type for argument 1 of ‘fun’
    fun(WW);
    ^~
    main.c:12:10: note: expected ‘struct MansWear’ but argument is of type ‘struct WomensWear’
    void fun(struct MansWear);


  1. What will be the output of the following C code? (Assuming size of int be 4)
    #include <stdio.h>
    struct Count
    {
    int n1;
    int n2;
    int n3;
    } cnt[] = {0};
    main()
    {
    printf("%d", sizeof(cnt));
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    12



  1. Which of the following uses structure?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Linked Lists, Array of structures and Binary Tree uses structure.


  1. What is the correct syntax to declare a function fun() which receives an array of structure in function?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    void fun(struct *num);



  1. Comment on the output of the following C code.
    #include <stdio.h>
    struct Number
    {
    int n1;
    int n2;
    int n3;
    };
    main()
    {
    struct Number num[] = {{12, 22, 32}, {24, 25, 26}, {27, 28, 29}};
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    No Compile time error, generates an array of structure of size 3