Arrow Operator with Pointers in C/C++: 18 MCQs with answers
All 18 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 7 questions
Q1. Which statement best describes a structure in C?
BeginnerShow answer & explanation
A user-defined type grouping different data types under one name
A structure is a user-defined data type that groups variables of different data types under a single name. It is not a built-in type, a function, or a loop.
Q2. In the definition `struct Student { char name[50]; int rollNo; };`, what is `Student` called?
BeginnerShow answer & explanation
The structure tag
`Student` is the structure tag — the name of the blueprint. No variable is created by this definition alone.
Q3. Which operator is used to access a member of a structure variable?
BeginnerShow answer & explanation
The dot operator (`.`)
The dot operator accesses members of a structure variable, e.g. `s1.rollNo`.
Q4. Which operator accesses a member through a pointer to a structure?
BeginnerShow answer & explanation
The arrow operator (`->`)
The arrow operator (`->`) accesses members through a pointer, e.g. `ptr->rollNo`.
Q5. Consider the following code: ```c struct Student { int rollNo; float marks; }; struct Student s1; s1.rollNo = 101; ``` What does `s1.rollNo` refer to?
BeginnerShow answer & explanation
The `rollNo` member of the structure variable `s1`
`s1.rollNo` uses the dot operator on a structure variable to name its `rollNo` member.
Q6. A program defines `struct Student` but never declares any variable of that type. How much memory does the structure definition itself allocate?
BeginnerShow answer & explanation
No memory at all
A structure definition is only a blueprint. Memory is allocated only when a variable of that structure type is declared.
Q7. `ptr->member` is exactly equivalent to `(*ptr).member`; the arrow operator is shorthand for dereferencing a pointer and then accessing a member.
BeginnerShow answer & explanation
True
`ptr->member` is exactly equivalent to `(*ptr).member`; the arrow operator is shorthand for dereferencing a pointer and then accessing a member.
Building up · 6 questions
Q8. Which line correctly declares a pointer to a structure and points it at `s1`?
IntermediateShow answer & explanation
`struct Student *ptr = &s1;`
A pointer to a structure is declared with `*` and assigned the address of the structure using `&s1`.
Q9. Which expression is exactly equivalent to `ptr->rollNo`?
IntermediateShow answer & explanation
`(*ptr).rollNo`
`ptr->rollNo` is shorthand for `(*ptr).rollNo` — dereference the pointer, then access the member.
Q10. Why are the parentheses required in `(*ptr).rollNo`?
IntermediateShow answer & explanation
Because `.` binds tighter than `*`, so `*ptr.rollNo` would be parsed incorrectly
The dot operator has higher precedence than `*`. Without parentheses, `*ptr.rollNo` means `*(ptr.rollNo)`, which is wrong.
Q11. A function needs to modify a large structure owned by the caller. Which approach is preferred?
IntermediateShow answer & explanation
Pass a pointer to the structure and use `->` inside
Passing a pointer copies only an address and lets the function modify the caller's structure directly.
Q12. Consider the following code: ```c struct Student s1 = {"Asha", 101, 87.5}; struct Student *ptr = &s1; ptr->marks = 92.0; printf("%.1f", s1.marks); ``` What is printed?
IntermediateShow answer & explanation
`92.0`
`ptr` points at `s1`, so `ptr->marks = 92.0` updates `s1.marks`. They share the same memory.
Q13. A student writes `ptr.rollNo` where `ptr` is declared as `struct Student *ptr;`. What happens?
IntermediateShow answer & explanation
A compile error, because the dot operator needs a structure variable
The dot operator cannot be applied to a pointer to a structure. The compiler rejects `ptr.rollNo`; the correct form is `ptr->rollNo`.
Topper level · 5 questions
Q14. Which statement about passing a structure by value versus by pointer is correct?
AdvancedShow answer & explanation
By value copies all members; by pointer copies only an address
Passing by value copies every member of the structure; passing a pointer copies just the address, which is far cheaper for large structures.
Q15. A linked list node is typically a structure that contains data and a pointer to the next node. Why is the arrow operator essential here?
AdvancedShow answer & explanation
Because nodes are reached through pointers, so `->` is the natural member access
In a linked list, you hold a pointer to a node, so you reach its members with `->`. The dot operator is only for structure variables, not pointers.
Q16. Assertion (A): `ptr->member` and `(*ptr).member` produce the same result. Reason (R): The arrow operator is defined as shorthand for dereferencing a pointer and then accessing a member.
AdvancedShow answer & explanation
Both A and R are true, and R correctly explains A
`ptr->member` is exactly equivalent to `(*ptr).member`, and this equivalence holds precisely because the arrow operator was introduced as shorthand for that dereference-plus-access operation.
Q17. Given the following code snippet, what will be the output when the program is executed? ```c struct Student { char name[50]; int rollNo; float marks; }; struct Student s1 = {"John", 102, 88.0}; struct Student *ptr = &s1; ptr->marks += 5.0; printf("%.1f\n", s1.marks); ```
AdvancedShow answer & explanation
93.0
The correct option is 93.0 because the line `ptr->marks += 5.0;` modifies `s1.marks` directly. Initially, `s1.marks` is 88.0, and adding 5.0 results in 93.0.
Q18. Analyze the following code segment. What will happen if the function `updateRollNo` is called with a pointer to `s1`? ```c void updateRollNo(struct Student *p, int newRollNo) { p->rollNo = newRollNo; } struct Student s1 = {"Alice", 101, 90.0}; updateRollNo(&s1, 105); printf("%d\n", s1.rollNo); ```
AdvancedShow answer & explanation
The program will compile and print 105
The correct option is 105 because the function `updateRollNo` modifies the `rollNo` member of `s1` directly through the pointer. The call `updateRollNo(&s1, 105);` updates `s1.rollNo` to 105, which is then printed.
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, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages