
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Explain the concept of Array of Pointer and Pointer to Pointer in C programming
Array Of Pointers
Just like any other data type, we can also declare a pointer array.
Declaration
datatype *pointername [size];
For example, int *p[5]; //It represents an array of pointers that can hold 5 integer element addresses
Initialization
The ‘&’ is used for initialization
For example,
int a[3] = {10,20,30}; int *p[3], i; for (i=0; i<3; i++) (or) for (i=0; i<3,i++) p[i] = &a[i]; p[i] = a+i;
Accessing
Indirection operator (*) is used for accessing.
For example,
for (i=0, i<3; i++) printf ("%d" *p[i]);
Example
#include<stdio.h> main (){ int a[3] = {10,20,30}; int *p[3],i; for (i=0; i<3; i++) p[i] = &a[i]; //initializing base address of array printf (elements of the array are”) for (i=0; i<3; i++) printf ("%d \t", *p[i]); //printing array of pointers getch(); }
Output
elements at the array are : 10 20 30
Pointer to Pointer
Pointer to pointer is a variable that holds the address of another pointer.
Declaration
datatype ** pointer_name;
For example, int **p; //p is a pointer to pointer
Initialization
The ‘&’ is used for initialization.
Eg −
int a = 10; int *p; int **q; p = &a;
Accessing
Indirection operator (*) is used for accessing.
Example
#include<stdio.h> main (){ int a = 10; int *p; int **q; p = &a; q = &p; printf("a =%d",a); printf("a value through pointer = %d", *p); printf("a value through pointer to pointer = %d", **q); }
Output
a=10 a value through pointer = 10 a value through pointer to pointer = 10
- Related Articles
- Explain the concept of pointer to pointer and void pointer in C language?
- Explain the concept of pointer accessing in C language
- Explain reference and pointer in C programming?
- Double Pointer (Pointer to Pointer) in C
- How to define pointer to pointer in C language?
- Pointer vs Array in C
- Pointer to an Array in C
- C program to display relation between pointer to pointer
- Explain the Union to pointer in C language
- Difference between pointer and array in C
- Differentiate the NULL pointer with Void pointer in C language
- Null Pointer Exception in Java Programming
- Sum of array using pointer arithmetic in C++
- Sum of array using pointer arithmetic in C
- Difference Between Array and Pointer

Advertisements