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?

Beginner
A A user-defined type grouping different data types under one name B A built-in type that stores only integers C A function that returns multiple values D A loop that repeats a block of code
Show 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?

Beginner
A The structure tag B A pointer to the structure C A structure variable D A member name
Show 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?

Beginner
A The dot operator (`.`) B The address-of operator (`&`) C The arrow operator (`->`) D The dereference operator (`*`)
Show 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?

Beginner
A The dot operator (`.`) B The logical AND operator (`&&`) C The modulo operator (`%`) D The arrow operator (`->`)
Show 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?

Beginner
A A pointer to the `rollNo` member B The address of the structure `s1` C The `rollNo` member of the structure variable `s1` D The size of the structure in bytes
Show 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?

Beginner
A Memory equal to the sum of all members B Memory equal to the largest member C Memory equal to one pointer D No memory at all
Show 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.

Beginner
A True B False
Show 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`?

Intermediate
A `struct Student *ptr = &s1;` B `struct Student ptr = &s1;` C `Student *ptr = s1;` D `struct Student *ptr = s1;`
Show 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`?

Intermediate
A `(*ptr).rollNo` B `ptr.rollNo` C `&ptr.rollNo` D `*ptr.rollNo`
Show 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`?

Intermediate
A Because pointers cannot be dereferenced without parentheses B Because `.` binds tighter than `*`, so `*ptr.rollNo` would be parsed incorrectly C Because `*` is not allowed next to a member name D Because the structure tag must be repeated inside the parentheses
Show 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?

Intermediate
A Pass each member separately as its own argument B Declare the structure as a local variable inside the function C Pass the structure by value and return the modified copy D Pass a pointer to the structure and use `->` inside
Show 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?

Intermediate
A A compile error occurs B `92.0` C `87.5` D `101.0`
Show 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?

Intermediate
A A compile error, because the dot operator needs a structure variable B It works and accesses the same member as `ptr->rollNo` C It compiles but prints garbage at runtime D It silently converts `ptr` into a structure variable
Show 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?

Advanced
A By value copies all members; by pointer copies only an address B By value copies only an address; by pointer copies all members C Both copy only an address, but by value is safer D Both copy all members, but by pointer is faster
Show 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?

Advanced
A Because `->` allocates memory for the next node automatically B Because the dot operator cannot be used with any structure C Because nodes are reached through pointers, so `->` is the natural member access D Because `->` compares two nodes for equality
Show 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.

Advanced
A A is true but R is false B A is false but R is true C Both A and R are true, but R does not explain A D Both A and R are true, and R correctly explains A
Show 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); ```

Advanced
A 93.0 B 88.0 C 87.0 D 92.0
Show 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); ```

Advanced
A The program will compile but print 101 B The program will compile but print 90 C The program will compile and print 105 D The program will not compile due to an error
Show 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.

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, 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