Structures and Unions Interview Questions

    Question 1Structure Basics

    What is a structure in C?

    Question 2Structure Declaration

    Which is the correct way to declare a structure?

    Question 3Structure Access

    What will be the output?

    #include <stdio.h> struct Point { int x, y; }; int main() { struct Point p = {10, 20}; printf("%d %d", p.x, p.y); return 0; }

    Question 4Pointer to Structure

    What will be printed?

    #include <stdio.h> struct Student { int id; }; int main() { struct Student s = {101}; struct Student *p = &s; printf("%d", p->id); return 0; }

    Question 5Difference between Structure and Union

    What is the key difference between structure and union in C?

    Question 6Size of Structure

    What will sizeof return?

    #include <stdio.h> struct Test { int a; char b; }; int main() { printf("%zu", sizeof(struct Test)); return 0; }

    Question 7Union Behavior

    What will be printed?

    #include <stdio.h> union Data { int i; char c; }; int main() { union Data d; d.i = 65; printf("%c", d.c); return 0; }

    Question 8Nested Structures

    Which of the following is valid for nested structures?

    Question 9Structure vs Array

    Which statement is true?

    Question 10Union Size

    What will sizeof return?

    #include <stdio.h> union U { int a; double b; char c; }; int main() { printf("%zu", sizeof(union U)); return 0; }