---
title: "Dot and arrow operators"
subject: "Computer Programming"
chapter: 8
key: "semester_1/computer_programming:dot-arrow-operators"
source: https://www.bctengineer.com/q/semester_1/computer_programming/dot-arrow-operators
site: BCT Engineering
---

# Dot and arrow operators

Computer Programming · Chapter 8: Structures

- Asked in: 2072 Kartik, 3 marks
- Video: [Structure Pointer, using Dot vs Arrow Operator | C Programming Language Tutorial](https://www.youtube.com/watch?v=k3hZELZg4_U) — LearningLad
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/dot-arrow-operators
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-8

## Question

Explain dot and arrow operators for accessing the members of a structure.

## Short answer

Dot operator (.) accesses members of a structure variable, e.g., var.member. Arrow operator (->) accesses members through a structure pointer: ptr->member, equivalent to (*ptr).member. Use dot for structure itself, arrow for a pointer.

## Answer

**Dot operator (.)**
It is the member access operator used with a structure **variable**: `variable.member`.

**Arrow operator (->)**
It is used with a **pointer to a structure**: `pointer->member`. It is the same as dereferencing the pointer first, `(*pointer).member`. The brackets are required because `.` has higher precedence than `*`.

```c
#include <stdio.h>

struct point {
    int x, y;
};

int main(void)
{
    struct point p = {3, 4};
    struct point *ptr = &p;

    printf("Using dot   : %d %d\n", p.x, p.y);
    printf("Using arrow : %d %d\n", ptr->x, ptr->y);
    printf("Same as     : %d %d\n", (*ptr).x, (*ptr).y);
    return 0;
}
```

Output:

```text
Using dot   : 3 4
Using arrow : 3 4
Same as     : 3 4
```

Use the dot when you have the structure itself, and the arrow when you have its address (for example in a function that receives a structure pointer, or with dynamic memory).

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. The dot operator is used with?
   A. A pointer to a structure
   B. An array only
   C. A structure variable
   D. A function name
   Answer: C. Syntax: variable.member (Key point: Dot operator)

2. The arrow operator is used with?
   A. A structure variable
   B. A string
   C. An int
   D. A pointer to a structure
   Answer: D. Syntax: pointer->member (Key point: Arrow operator)

3. Why are brackets needed in (*pointer).member?
   A. The dot has higher precedence than *
   B. * has higher precedence than the dot
   C. They are optional
   D. To make it faster
   Answer: A. Without brackets *pointer.member would apply . first. (Key point: Brackets)

## Related in Computer Programming

- [Structure vs array; accessing members](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astructure-vs-array-access-members) — Computer Programming, chapter 8
- [Sending structure members to a function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astructure-members-to-function) — Computer Programming, chapter 8

## Related in other subjects

- [Distance class relational operators](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Adistance-relational-overload) — Object Oriented Programming, chapter 5
