## Pointer with Array in C

Preview
You must first complete for statement in c language | Nesting of for in c language before viewing this Lesson

# Pointer with Array in C

Pointers are associated closely with arrays because arrays are implemented internally in the form of pointers.

One dimensional array with Pointer

Suppose we have a one dimensional array as

int a={10,33,55,07};

We can refer to array elements as:

a can be referred as *(a+0)
a can be referred as *(a+1)
a can be referred as *(a+2)
and so on..

 Program #include int main() { int a={15,71,18,90};printf(“\n%u”,a); /*Address of a*/ printf(“\n%u”,&a); /*Address of a*/printf(“\n%d”,*a); /*Value of a*/ printf(“\n%d”,*(a+0)); /*Value of a*/printf(“\n%u”,(a+1)); /*Address of a*/ printf(“\n%d”,*(a+1)); /*Value of a*/printf(“\n%u”,(a+2)); /*Address of a*/ printf(“\n%d”,*(a+2)); /*Value of a*/printf(“\n%u”,(a+3)); /*Address of a*/ printf(“\n%d”,*(a+3)); /*Value of a*/return(0); }

## Two dimensional array with pointer

Suppose that we have a two dimensional array initialized as
int a={10,20,30,40};
We can also refer to array elements with the help of pointers as:
a can be referred as *(*(a+0)+0)
a can be referred as *(*(a+0)+1)
a can be referred as *(*(a+1)+0)
a can be referred as *(*(a+1)+1)

 Program #include int main() {int arr={10,20,30,40};printf(“\n%u”,arr); /*Address of arr*/ printf(“\n%u”,arr); /*Address of arr*/ printf(“\n%u”,&arr); /*Address of arr*/printf(“\n%d”,*(*(arr+0)+0)); /*Value of arr*/ printf(“\n%d”,*(*(arr+0)+1)); /*Value of arr*/ printf(“\n%d”,*(*(arr+1)+0)); /*Value of arr*/ printf(“\n%d”,*(*(arr+1)+1)); /*Value of a*/return(0); }

## Best Sellers

Lesson tags: one dimensional array with pointer in c, pointer array in c, pointer with array in c, two dimensional array with pointer in c
Back to: C Programming Language