---
title: "Array of pointers"
subject: "Computer Programming"
chapter: 9
key: "semester_1/computer_programming:array-of-pointers"
source: https://www.bctengineer.com/q/semester_1/computer_programming/array-of-pointers
site: BCT Engineering
---

# Array of pointers

Computer Programming · Chapter 9: Pointers

- Asked in: 2070 Chaitra, 5 marks
- Video: [Array of Pointers, Character Array in C Programming with examples | C language in Hindi](https://www.youtube.com/watch?v=cqX54iGlqBY) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/array-of-pointers
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-9

## Question

Briefly explain array of pointers.

## Short answer

An array of pointers stores memory addresses as elements. Declared as data_type *name[size]; it is commonly used for arrays of strings or command-line arguments, allowing efficient manipulation like sorting by swapping only pointers, not the actual data.

## Answer

An **array of pointers** is an array whose elements are all pointers, each holding the address of a variable or a string.

**Declaration:** `data_type *name[size];` for example `int *p[3];` is an array of 3 pointers to integers.

```c
int x = 10, y = 20, z = 30;
int *p[3] = {&x, &y, &z};     /* p[i] stores the address of x, y, z */
printf("%d", *p[1]);          /* prints 20 */
```

The commonest use is an array of strings, where each pointer points to a string, and strings of different lengths need no wasted space:

```c
char *day[3] = {"Sunday", "Monday", "Tuesday"};
```
Sorting these strings only needs the pointers to be swapped, not the characters. It is also used for arrays of structure pointers and `argv` (command line arguments).

```c
#include <stdio.h>

int main(void)
{
    char *day[3] = {"Sunday", "Monday", "Tuesday"};   /* array of 3 pointers */
    int x = 10, y = 20, z = 30;
    int *p[3] = {&x, &y, &z};

    for (int i = 0; i < 3; i++)
        printf("%s  %d\n", day[i], *p[i]);
    return 0;
}
```

Output:

```text
Sunday  10
Monday  20
Tuesday  30
```

## Check yourself

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

1. What does int *p[3]; declare?
   A. A pointer to an array of 3 ints
   B. An array of 3 pointers to int
   C. An array of 3 ints
   D. A function with 3 arguments
   Answer: B. Each of the 3 elements is a pointer holding the address of an integer. (Key point: Meaning of int *p[3];)

2. With int x=10,y=20,z=30; int *p[3]={&x,&y,&z};, what does printf("%d", *p[1]) print?
   A. 10
   B. 20
   C. 30
   D. The address of y
   Answer: B. p[1] holds &y, and *p[1] is the value at that address, 20. (Key point: Value through array of pointers)

3. What is the commonest use of an array of pointers?
   A. Storing an array of strings of different lengths without wasted space
   B. Storing only integers
   C. Making arrays constant
   D. Avoiding pointers
   Answer: A. Each pointer points to a string, so strings of different lengths need no padding. (Key point: Commonest use)

4. When sorting an array of strings held as char *day[], what is exchanged?
   A. Every character of each string
   B. Only the pointers
   C. The array size
   D. Nothing; sorting is impossible
   Answer: B. Only the pointers are swapped, which is quicker than moving the characters. (Key point: Sorting strings)

## 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
- [Accessing array elements using pointer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-access-array-elements) — Computer Programming, chapter 9
