### 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("address of i=%u or p=%u\n",&i,p);
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("\nAddresses of integers:\n");
printf("address of a=%u\n",&a);
printf("address of b=%u\n",&b);
printf("address of c=%u\n",&c);

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

printf("\nsince arr[i] are address so *arr[i] gives values stored at address stored in them\n");
printf("\narr=%u\n",*arr);
printf("arr=%u\n",*arr);
printf("arr=%u\n",*arr);
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
address of i=3220971004 or p=3220971004
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

Addresses of integers:
address of a=3220971008
address of b=3220971012
address of c=3220971016

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

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

arr=10
arr=20
arr=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;
}