ointer_arrays

C Pointers and Arrays

C Pointers and Arrays

In C, arrays and pointers are closely related. Pointers can be used to access elements in an array.

Using Pointers with Arrays

#include 

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    int *ptr = arr;

    for (int i = 0; i < 5; i++) {
        printf("Element %d: %d\n", i + 1, *(ptr + i));
    }

    return 0;
}
    

This program demonstrates how to use pointers to access elements in an array.