Saturday 5 June 2021

Array of pointers - How to store address in array in C

 Like normal values, address are also stored in array. If an array contains address then it is called array of pointers. There may be a situations where we need to store so many address in a single group. At this point of time, array of pointers are more useful.

Let us consider the following example,

int a,b,c;

a=10; b=20; c=30

An array of pointer to store these variables address can be declared like this

int *ptr[5];

we can assign variable addresses to array as

ptr[0]=&a; ptr[1]=&b; ptr[2]=&c;

As shown like above figure, in the zero location the array can store the address of variable 'a' and next location address of 'ab' ext. To print the value stored in value used indirection operator (*) along with pointer variable name like 

for(i=0;0<3;i++)

printf("%d",*ptr[i]);

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top