Structures


  1. What will be the output of the following C code?
    #include <stdio.h>
    struct Cricket_Team
    {
    int A;
    int B;
    } t[] = {150, 250, 350, 450, 550};
    void function(struct Cricket_Team*);
    int main()
    {
    function(t);
    }
    void function(struct Cricket_Team t[])
    {
    printf("%d %d\n", t->A, t[2].B);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    150 0


  1. What will be the output of the following C code?
     #include &l;stdio.h>
    struct Price
    {
    int m;
    int n;
    };
    void fun(struct Price*);
    int main()
    {
    struct Price p1[] = {105, 210, 310, 49, 59};
    fun(p1);
    }
    void fun(struct Price p[])
    {
    printf("%d %d\n", p->m, p[3].n);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    105 0



  1. What will be the output of the following C code?
    #include <stdio.h>
    struct Count
    {
    int m;
    int n;
    };
    void fun(struct Count*);
    int main()
    {
    struct Count c1[] = {14, 24, 34, 44, 54};
    fun(c1);
    }
    void fun(struct Count c2[])
    {
    printf("%d %d\n", c2->m, (c2 + 2).n);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    Compilation Error

    main.c: In function ‘fun’:
    main.c:15:42: error: ‘c2 + 16’ is a pointer; did you mean to use ‘->’?
    printf("%d %d\n", c2->m, (c2 + 2).n);


  1. What will be the output of the following C code?
    #include <stdio.h>
    struct Option
    {
    int t1;
    int t2;
    };
    void fun(struct Option*);
    int main()
    {
    struct Option opt1[] = {12, 22, 23, 24, 25};
    fun(opt1);
    }
    void fun(struct Option opt[])
    {
    printf("%d %d\n", opt->t1, (opt + 2)->t2);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    12 0



  1. What will be the output of the following C code?
    #include <stdio.h>
    struct alphabet
    {
    char *ch;
    };
    void main()
    {
    struct alphabet alp[2];
    printf("%d", sizeof(alp));
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    16