structure in c language: 36 MCQs

All 36 multiple-choice questions from this kit, free and with no sign-up.

Warm-up · 21 questions

Q1. What is the primary purpose of a structure in C?

Beginner
A To group variables of different types under a single name
B To perform arithmetic operations
C To store a single data type
D To replace arrays

Answers and explanations are in the Veda app.

Q2. Which keyword is used to define a structure?

Beginner
A `typedef`
B `struct`
C `enum`
D `union`

Answers and explanations are in the Veda app.

Q3. When is memory allocated for a structure?

Beginner
A When a structure variable is declared
B When the program starts
C When the structure is defined
D When the structure is passed to a function

Answers and explanations are in the Veda app.

Q4. Which operator is used to access a member of a structure variable?

Beginner
A `->`
B `.`
C `::`
D `#`

Answers and explanations are in the Veda app.

Q5. What does `ptr->member` mean in terms of dereferencing?

Beginner
A `*(ptr.member)`
B `&(ptr->member)`
C `(*ptr).member`
D `ptr.member`

Answers and explanations are in the Veda app.

Q6. What is the effect of `typedef struct Student Student;`?

Beginner
A It creates a new structure called Student
B It allocates memory for a Student
C It makes `struct` optional in all declarations
D It creates an alias `Student` for `struct Student`

Answers and explanations are in the Veda app.

Q7. Why might the size of a structure be larger than the sum of its members' sizes?

Beginner
A Because structures always include a hidden pointer
B Because of padding for memory alignment
C Because of compiler optimizations
D Because of runtime overhead

Answers and explanations are in the Veda app.

Q8. Which of the following is a valid way to pass a structure to a function without copying the entire structure?

Beginner
A Pass a pointer to the structure
B Pass the structure by reference using `&` in the function call
C Pass the structure by value
D Pass the structure as a global variable

Answers and explanations are in the Veda app.

Q9. What happens when you assign one structure variable to another (e.g., `s2 = s1;`)?

Beginner
A It creates a reference to s1
B It is not allowed in C
C It copies all members from s1 to s2
D It compares the two structures

Answers and explanations are in the Veda app.

Q10. Structures can be compared directly with the `==` operator in C.

Beginner
A True
B False

Answers and explanations are in the Veda app.

Q11. The arrow operator (`->`) is equivalent to dereferencing a pointer and then using the dot operator.

Beginner
A True
B False

Answers and explanations are in the Veda app.

Q12. What is a structure in C?

Beginner

Answers and explanations are in the Veda app.

Q13. Does defining a structure allocate memory? Explain.

Beginner

Answers and explanations are in the Veda app.

Q14. How do you access a member of a structure variable?

Beginner

Answers and explanations are in the Veda app.

Q15. How do you access a member through a pointer to a structure?

Beginner

Answers and explanations are in the Veda app.

Q16. How can you create an alias for a structure?

Beginner

Answers and explanations are in the Veda app.

Q17. Is structure assignment allowed in C? What does it do?

Beginner

Answers and explanations are in the Veda app.

Q18. How do you initialize a structure variable at declaration? Give an example.

Beginner

Answers and explanations are in the Veda app.

Q19. What is the difference between the dot operator and the arrow operator?

Beginner

Answers and explanations are in the Veda app.

Q20. Can a structure contain an array as a member?

Beginner

Answers and explanations are in the Veda app.

Q21. How do you access a member of an array of structures?

Beginner

Answers and explanations are in the Veda app.

Building up · 10 questions

Q22. What is the equivalence of `ptr->member`?

Intermediate

Answers and explanations are in the Veda app.

Q23. Can structures be compared directly with `==`? Why or why not?

Intermediate

Answers and explanations are in the Veda app.

Q24. Why might the size of a structure be larger than the sum of its members' sizes?

Intermediate

Answers and explanations are in the Veda app.

Q25. What is the advantage of passing a structure by pointer to a function?

Intermediate

Answers and explanations are in the Veda app.

Q26. What is the foundation for implementing linked lists in C?

Intermediate

Answers and explanations are in the Veda app.

Q27. Given the following structure definition and code snippet, what will be the output? ```c struct Point { int x; int y; }; int main() { struct Point p1 = {10, 20}; struct Point p2; p2 = p1; p2.x = 30; printf("%d %d\n", p1.x, p2.x); return 0; } ```

Intermediate
A Compilation error
B 10 30
C 10 10
D 30 30

Answers and explanations are in the Veda app.

Q28. Which of the following correctly initializes a structure variable at declaration and then accesses a member using a pointer? ```c struct Student { char name[50]; int roll; }; ```

Intermediate
A `struct Student s = {"Alice", 101}; struct Student *ptr = &s; printf("%s", *ptr.name);`
B `struct Student s = {"Alice", 101}; struct Student *ptr = &s; printf("%s", ptr.name);`
C `struct Student s = {"Alice", 101}; struct Student *ptr = s; printf("%s", ptr.name);`
D `struct Student s = {"Alice", 101}; struct Student *ptr = &s; printf("%s", ptr->name);`

Answers and explanations are in the Veda app.

Q29. Consider the following structure: ```c struct Data { char c; int i; double d; }; ``` On a typical 64-bit system with default alignment, which of the following statements about `sizeof(struct Data)` is true?

Intermediate
A It is smaller than 13 bytes because the compiler packs members tightly.
B It is larger than 13 bytes due to padding inserted by the compiler for alignment.
C It is exactly equal to `sizeof(char) + sizeof(int) + sizeof(double)` = 13 bytes.
D It is undefined behavior to call `sizeof` on a structure.

Answers and explanations are in the Veda app.

Q30. What is the primary advantage of passing a pointer to a structure to a function instead of passing the structure by value?

Intermediate
A It avoids the need to use the arrow operator inside the function.
B It automatically initializes the structure to zero.
C It allows the function to modify the original structure.
D It makes the function run faster because pointers are always faster than values.

Answers and explanations are in the Veda app.

Q31. Which of the following code snippets correctly defines a structure with an alias using `typedef` and then declares a variable of that type?

Intermediate
A ```c struct Point { int x; int y; }; typedef Point; Point p; ```
B ```c struct Point { int x; int y; }; typedef struct Point Point; struct Point p; ```
C ```c typedef struct Point { int x; int y; }; Point p; ```
D ```c typedef struct { int x; int y; } Point; Point p; ```

Answers and explanations are in the Veda app.

Topper level · 5 questions

Q32. Consider the following code snippet: ```c struct Node { int data; struct Node *next; }; void insertAfter(struct Node *prev, int value) { struct Node *newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = value; newNode->next = prev->next; prev->next = newNode; } ``` If `head` points to the first node of a linked list and we call `insertAfter(head, 5)`, what is the effect on the list?

Advanced
A The new node is inserted at the beginning of the list.
B The new node replaces the first node, and the original first node is lost.
C The new node is inserted after the first node, and the original second node becomes the third node.
D The new node is inserted at the end of the list.

Answers and explanations are in the Veda app.

Q33. Given the following structure and function: ```c struct Employee { char name[50]; int id; float salary; }; void updateSalary(struct Employee *e, float newSalary) { e->salary = newSalary; } ``` Which of the following statements is true about the function `updateSalary`?

Advanced
A It modifies a copy of the structure, so the original remains unchanged.
B It will not compile because you cannot use the arrow operator on a pointer to a structure.
C It only works if the structure is defined globally.
D It modifies the salary of the original structure because it receives a pointer to the structure.

Answers and explanations are in the Veda app.

Q34. Consider the following structure and code: ```c struct Data { char a; int b; char c; }; int main() { struct Data d = {'x', 10, 'y'}; printf("%zu\n", sizeof(d)); return 0; } ``` On a typical 64-bit system with default alignment (where `int` is 4 bytes and alignment is 4 bytes), what will be the output?

Advanced
A 16
B 6
C 12
D 8

Answers and explanations are in the Veda app.

Q35. Which of the following code snippets correctly defines a structure with an alias using `typedef` and then declares a variable of that type?

Advanced
A ```c typedef struct { int x; int y; } Point; Point p; ```
B ```c struct Point { int x; int y; }; typedef Point; Point p; ```
C ```c struct Point { int x; int y; } typedef Point; Point p; ```
D ```c typedef struct Point { int x; int y; }; struct Point p; ```

Answers and explanations are in the Veda app.

Q36. Consider the following code: ```c struct Student { char name[50]; int roll; }; void printStudent(struct Student s) { printf("%s %d\n", s.name, s.roll); } int main() { struct Student s1 = {"Alice", 101}; printStudent(s1); return 0; } ``` What is a potential drawback of passing `s1` to `printStudent` in this manner?

Advanced
A It will not compile because structures cannot be passed to functions by value.
B It modifies the original structure `s1` because the function receives a reference.
C It copies the entire structure, which can be inefficient for large structures.
D It only works if the structure is defined inside the function.

Answers and explanations are in the Veda app.

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free to start, in more than 40 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Paper Solver

Get Veda free See what students get

Free to start · Android app and web · More than 40 languages