Structures


  1. What will be the output of the following C code?
     #include <stdio.h>
    struct output
    {
    int n1;
    char n2;
    };
    int main(){
    struct output out[] = {100, 90, 13, 95, 55, 92};
    struct output *ptr1 = out;
    int n1 = (sizeof(out) / sizeof(struct output));
    printf("%d %d\n", ptr1->n1, (ptr1 + n1 - 1)->n1);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    100 55


  1. What will be the output of the following C code?
    #include <stdio.h>
    struct Company
    {
    char *ch;
    struct Company *point;
    };
    void main()
    {
    struct Company c1;
    struct Company c2;
    c1.ch = c2.ch = "Interview";
    c2.point = &c1;
    (c2.point)->ch = "Mania";
    printf("%s %s\t", c1.ch, c2.ch);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Mania Interview



  1. What will be the output of the following C code?
    #include <stdio.h>
    struct Employee
    {
    char *ch;
    struct Employee *point;
    };
    void main()
    {
    struct Employee e1;
    struct Employee e2;
    e2.point = e1;
    (e2.point)->ch = "Prayag";
    printf("%s", e1.ch);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Compilation Error

    main.c: In function ‘main’:
    main.c:11:18: error: incompatible types when assigning to type ‘struct Employee *’ from type ‘struct Employee’
    e2.point = e1;


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    16



  1. What will be the output of the following C code?
    #include <stdio.h>
    struct Employee
    {
    char *ch;
    };
    void main()
    {
    struct Employee *e;
    e->ch = "Prayag";
    printf("%s", e->ch);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Segmentation fault