Yes, by holding the base address of array into a pointer, we can access the array using a pointer.
Yes, in C language, you can access an array using a pointer. In fact, arrays and pointers are closely related in C. When you declare an array, it can decay into a pointer to its first element in many contexts.
For example:
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr; // assigning the base address of the array to the pointer
// Accessing elements of the array using pointer notation
printf("%d\n", *ptr); // prints the first element of the array, which is 1
printf("%d\n", *(ptr + 1)); // prints the second element of the array, which is 2
// Or using array notation
printf("%d\n", arr[0]); // prints the first element of the array, which is 1
printf("%d\n", arr[1]); // prints the second element of the array, which is 2
In this example, ptr
is a pointer that points to the first element of the array arr
. You can use pointer arithmetic or array subscripting to access elements of the array through the pointer. So, yes, you can access an array using a pointer in C.