#include <stdio.h>
int main() {
//57. Write a program to access elements using pointer.
printf("\tElements Of Array\n");
printf("===================================\n\n");
int arr[5] = {18, 19, 20, 21, 22};
int *ptr;
int i;
ptr = arr;
for (i = 0; i < 5; i++) {
printf("\nThe value of element %d is: %d\n", i, *(ptr + i));
}
return 0;
}
stdio.h
.main()
function is defined.int
data type are declared: arr
which is an array of 5 integers, and ptr
which is a pointer to an integer.i
is declared.ptr
is initialized to the base address of the array arr
.for
loop is used to iterate over the array. The loop variable i
is used to index each element of the array.ptr
. The expression *(ptr + i)
gives the value of the i
-th element of the array.i
-th element is printed using printf()
function.main()
function returns an integer value 0.