#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
int *ptr = arr;
printf("Value of arr[0]: %d\n", arr[0]); // Output: Value of arr[0]: 10
printf("Value of ptr: %d\n", ptr); // Output: Value of *ptr: 10
ptr++; // Move the pointer to the next element in the array
printf("Value of arr[1]: %d\n", arr[1]); // Output: Value of arr[1]: 20
printf("Value of ptr: %d\n", ptr); // Output: Value of *ptr: 20
return 0;
}
- An array
arr
of integers is declared and initialized with values {10, 20, 30, 40, 50}
. - A pointer variable
ptr
of type integer is declared and assigned the memory address of the first element of the array arr
. - The
printf
function prints the value of arr[0]
, which is 10
, and the value pointed to by ptr
, which is also 10
. - The
ptr
is incremented by 1, which makes it point to the next element of the array. - Another set of
printf
functions print the value of arr[1]
, which is 20
, and the value pointed to by ptr
, which is also 20
.