---
title: "Structure vs array; accessing members"
subject: "Computer Programming"
chapter: 8
key: "semester_1/computer_programming:structure-vs-array-access-members"
source: https://www.bctengineer.com/q/semester_1/computer_programming/structure-vs-array-access-members
site: BCT Engineering
---

# Structure vs array; accessing members

Computer Programming · Chapter 8: Structures

- Asked in: 2074 Chaitra, 4 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/structure-vs-array-access-members
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-8

## Question

How does a structure differ from an array? What are the different ways to access structure member?

## Short answer

A structure groups different-type members, an array holds same-type elements. Access members via dot operator (s.member) with a variable, arrow operator (p->member) with a pointer, indexing then dot (arr[i].member) for an array of structures, and chained dots for nested members.

## Answer

#### Structure versus array
| Basis | Structure | Array |
|---|---|---|
| Element types | Different types allowed | Same type only |
| Declaration | `struct` keyword with members | `type name[size]` |
| Access | By member name | By index |
| Use | One record with many fields | A list of similar values |

#### Ways to access structure members
1. **Dot operator (.)** with a structure variable: `s1.roll = 5;`
2. **Arrow operator (->)** with a pointer to a structure: `ptr->roll = 5;`, which is the same as `(*ptr).roll`.
3. **Array of structures**: `s[2].roll`, using the index and then the dot.
4. **Nested structures**: dot repeated, `s1.dob.year`.

## Check yourself

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

1. Which statement is correct?
   A. Both allow only one type
   B. Arrays allow different types
   C. Structures are accessed by index
   D. A structure allows different member types; an array allows only one type
   Answer: D. Structure access is by name, array access by index. (Key point: Difference)

2. The dot operator is used with?
   A. A structure variable: s1.roll
   B. A pointer: ptr.roll
   C. Only arrays
   D. Only functions
   Answer: A. Dot works on the structure variable itself. (Key point: Dot operator)

3. ptr->roll is the same as?
   A. *ptr.roll
   B. (*ptr).roll
   C. &ptr.roll
   D. ptr.roll
   Answer: B. The arrow dereferences the pointer then accesses the member. (Key point: Arrow operator)

4. How is the year in a nested structure dob inside s1 accessed?
   A. s1->year
   B. dob.year.s1
   C. s1.dob.year
   D. s1.year
   Answer: C. Dots are repeated. (Key point: Nested access)

## Related in Computer Programming

- [Accessing array elements using pointer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-access-array-elements) — Computer Programming, chapter 9
- [Structure versus array](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astructure-vs-array) — Computer Programming, chapter 8, asked 4×
- [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
- [Declaration vs definition; C program structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adeclaration-definition-structure-of-c) — Computer Programming, chapter 3
- [Height difference using nested structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-height-feet-inches) — Computer Programming, chapter 8
- [College records with nested date structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-college-estdate) — Computer Programming, chapter 8

## Related in other subjects

- [Access overridden members from derived class](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aaccess-overridden-members) — Object Oriented Programming, chapter 6, asked 2×
- [Array representation vs dynamic list](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aarray-vs-dynamic-list) — Data Structure and Algorithm, chapter 3
- [Multiplexing vs multiple access](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Amux-vs-multiple-access) — Data Communication, chapter 6
- [CDMA vs TDMA; FHSS multiple access](https://www.bctengineer.com/question.md?key=semester_7%2Fwireless_communication%3Acdma-advantages-fhss-types) — Wireless Communication, chapter 7
