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?
BeginnerAnswers and explanations are in the Veda app.
Q2. Which keyword is used to define a structure?
BeginnerAnswers and explanations are in the Veda app.
Q3. When is memory allocated for a structure?
BeginnerAnswers and explanations are in the Veda app.
Q4. Which operator is used to access a member of a structure variable?
BeginnerAnswers and explanations are in the Veda app.
Q5. What does `ptr->member` mean in terms of dereferencing?
BeginnerAnswers and explanations are in the Veda app.
Q6. What is the effect of `typedef struct Student Student;`?
BeginnerAnswers and explanations are in the Veda app.
Q7. Why might the size of a structure be larger than the sum of its members' sizes?
BeginnerAnswers 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?
BeginnerAnswers and explanations are in the Veda app.
Q9. What happens when you assign one structure variable to another (e.g., `s2 = s1;`)?
BeginnerAnswers and explanations are in the Veda app.
Q10. Structures can be compared directly with the `==` operator in C.
BeginnerAnswers and explanations are in the Veda app.
Q11. The arrow operator (`->`) is equivalent to dereferencing a pointer and then using the dot operator.
BeginnerAnswers and explanations are in the Veda app.
Q13. Does defining a structure allocate memory? Explain.
BeginnerAnswers and explanations are in the Veda app.
Q14. How do you access a member of a structure variable?
BeginnerAnswers and explanations are in the Veda app.
Q15. How do you access a member through a pointer to a structure?
BeginnerAnswers and explanations are in the Veda app.
Q16. How can you create an alias for a structure?
BeginnerAnswers and explanations are in the Veda app.
Q17. Is structure assignment allowed in C? What does it do?
BeginnerAnswers and explanations are in the Veda app.
Q18. How do you initialize a structure variable at declaration? Give an example.
BeginnerAnswers and explanations are in the Veda app.
Q19. What is the difference between the dot operator and the arrow operator?
BeginnerAnswers and explanations are in the Veda app.
Q20. Can a structure contain an array as a member?
BeginnerAnswers and explanations are in the Veda app.
Q21. How do you access a member of an array of structures?
BeginnerAnswers and explanations are in the Veda app.
Building up · 10 questions
Q22. What is the equivalence of `ptr->member`?
IntermediateAnswers and explanations are in the Veda app.
Q23. Can structures be compared directly with `==`? Why or why not?
IntermediateAnswers and explanations are in the Veda app.
Q24. Why might the size of a structure be larger than the sum of its members' sizes?
IntermediateAnswers and explanations are in the Veda app.
Q25. What is the advantage of passing a structure by pointer to a function?
IntermediateAnswers and explanations are in the Veda app.
Q26. What is the foundation for implementing linked lists in C?
IntermediateAnswers 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; } ```
IntermediateAnswers 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; }; ```
IntermediateAnswers 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?
IntermediateAnswers 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?
IntermediateAnswers 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?
IntermediateAnswers 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?
AdvancedAnswers 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`?
AdvancedAnswers 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?
AdvancedAnswers 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?
AdvancedAnswers 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?
AdvancedAnswers and explanations are in the Veda app.
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