Pointer to an array of integers in C language
Learn C - C tutorial - pointer to an array of integers in c language - C examples - C programs
Pointer to an array of integers in C language
Pointer
- Pointer value refers to another value stored at computer memory using its memory address.
- A pointer references a location in memory and get the value stored at that location is known as dereferencing pointer.
Array
- Array is a kind of data structure that can store a fixed-size following in a logical order collection of elements of the same type.
- An array is used to store a collection of datas of same type.
For Example,
Learn C - C tutorial - pointer to an array of integers in c language - C examples - C programs
Sample Code
#include <stdio.h>
int main()
{
int arr[]= {10,20,30,40,50};
int *ptr,loop;
ptr = arr;//initialize ptr
for(loop=0; loop< 5; loop++)
printf("arr[%d]: %d\n",loop,*(ptr+loop));
return 0;
}
Output
arr[0]: 10
arr[1]: 20
arr[2]: 30
arr[3]: 40
arr[4]: 50