### Array of Pointers to integer in C

/*Array of pointers to integers i.e. Array of integer pointers. Since integer pointer store one address.So,array of integer pointers is used to store  many addresses .*/
#include<stdio.h>
int main()
{
printf("\nBefore starting array of pointers Understand pointer \n");
printf("\nint *p; tells to compiler that p will be used to store single address of integer\n");
int *p;//p will be used to store address of a pointer
int i=10;
p=&i;//pointer is used to store address of int i
printf("value of i=%d or *p=%u\n",i,*p);

printf("\nNow understanding array of pointer to integers.\n");
printf("\narray of pointers to integers is used to store many addresses of integers\n");
int a=10,b=20,c=30;
int* arr[]={&a,&b,&c};/*arr is array of integer pointers so contains addresses*/

printf("\nAddrs of integers are stored in arr so each arr[i] is an address:\n");
printf("arr[0]=%u\n",arr[0]);
printf("arr[1]=%u\n",arr[1]);
printf("arr[2]=%u\n",arr[2]);

printf("\nsince arr[i] are address so *arr[i] gives values stored at address stored in them\n");
printf("\narr[0]=%u\n",*arr[0]);
printf("arr[1]=%u\n",*arr[1]);
printf("arr[2]=%u\n",*arr[2]);
return 0;
}
/*OUTPUT:
Before starting array of pointers Understand pointer.
int *p; tells to compiler that p will be used to store single address of integer
value of i=10 or *p=10

Now understanding array of pointer to inegers.

array of pointers to integers is used to store many addreses of integers

Addrs of integers are stored in arr so each arr[i] is an address:
arr[0]=3220971008
arr[1]=3220971012
arr[2]=3220971016

since arr[i] are address so *arr[i] gives values stored at address stored in them

arr[0]=10
arr[1]=20
arr[2]=30
*/

#### 1 comment:

1. Array of Character Pointers ie
Array of Strings ie
Array of Pointers to chararcter

#include

const int MAX = 4;

int main ()
{
char *names[] = {
"clinuxcode",
"C Linux Code",
"For Array of pointer",
"pointer to array",
};
int i = 0;

for ( i = 0; i < MAX; i++)
{
printf("Value of names[%d] = %s\n", i, names[i] );
}
return 0;
}