---
title: "Accessing array elements using pointer"
subject: "Computer Programming"
chapter: 9
key: "semester_1/computer_programming:pointer-access-array-elements"
source: https://www.bctengineer.com/q/semester_1/computer_programming/pointer-access-array-elements
site: BCT Engineering
---

# Accessing array elements using pointer

Computer Programming · Chapter 9: Pointers

- Asked in: 2068 Chaitra, 1+1 marks
- Video: [Accessing Array Elements](https://www.youtube.com/watch?v=g0ClJ28-8LE) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/pointer-access-array-elements
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-9

## Question

Explain how pointers can be used in C. How can you access array elements using pointer.

## Short answer

Pointers hold addresses, enabling call by reference, dynamic memory, and efficient array handling. To access array elements, set a pointer to the array name (address of first element); then *(p+i) gives a[i], and pointer arithmetic like p++ traverses the array.

## Answer

#### Use of pointers in C
A pointer is a variable holding the address of another variable. It is used for call by reference, dynamic memory allocation (`malloc`), efficient array and string handling, and building data structures such as linked lists and trees.

#### Accessing array elements with a pointer
The array name is the address of its first element, so a pointer can be set to it: `int *p = a;`. Then:
- `*p` is `a[0]`, `*(p + 1)` is `a[1]`, and in general `*(p + i)` is `a[i]`.
- The pointer can be moved with `p++` to visit the next element.

```c
#include <stdio.h>

int main(void)
{
    int a[5] = {5, 10, 15, 20, 25}, *p = a, sum = 0;

    for (int i = 0; i < 5; i++)
        printf("a[%d] = %d\n", i, *(p + i));    /* value using pointer */

    for (p = a; p < a + 5; p++)                 /* moving the pointer */
        sum += *p;
    printf("Sum = %d\n", sum);
    return 0;
}
```

Output:

```text
a[0] = 5
a[1] = 10
a[2] = 15
a[3] = 20
a[4] = 25
Sum = 75
```

## Check yourself

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

1. How is a pointer set to an array a?
   A. int *p = &a;
   B. int *p = a;
   C. int *p = *a + 1;
   D. int p = a;
   Answer: B. The array name is the address of its first element, so int *p = a; makes p point to a[0]. (Key point: Pointer to array)

2. Which expression gives a[3] through p = a?
   A. *(p + 3)
   B. *p + 3
   C. p + 3
   D. &p[3]
   Answer: A. p + 3 is the address of the 4th element and * gives its value. (Key point: Element via pointer)

3. What does p++ do in the sum loop?
   A. Adds 1 to the current element's value
   B. Moves p to the next element
   C. Resets p to the start
   D. Frees the array
   Answer: B. It advances p by one element so *p is the next value. (Key point: Moving the pointer)

4. Which is NOT a use of pointers in C?
   A. Call by reference
   B. Dynamic memory allocation
   C. Building linked lists
   D. Automatically checking array bounds
   Answer: D. C pointers do no bounds checking; the others are standard uses. (Key point: Uses of pointers)

## Related in Computer Programming

- [Pointers in pass by reference; 2D array](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-passing-by-reference-2d) — Computer Programming, chapter 9
- [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
- [Array of pointers](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aarray-of-pointers) — Computer Programming, chapter 9
- [Relation between array and pointer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aarray-pointer-relation) — Computer Programming, chapter 9, asked 5×
- [Reverse array and display via pointer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-reverse-array) — Computer Programming, chapter 9
- [Second largest element using pointer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-second-largest) — Computer Programming, chapter 9

## Related in other subjects

- [Yagi parasitic elements and LPDA comparison](https://www.bctengineer.com/question.md?key=semester_6%2Fpropagation_and_antenna%3Ayagi-parasitic-elements-vs-lpda) — Propagation and Antenna, chapter 3, asked 3×
- [Access specifiers in inheritance](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aaccess-specifiers-inheritance) — Object Oriented Programming, chapter 6
- [Strowger subscriber access design approaches](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Astrowger-subscriber-access) — Telecommunications, chapter 1
- [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×
