Array Pointers in C: Definition & Usage
In C language, arrays pointers can be defined in two ways:
- Declaring an array using a pointer: You can first declare a pointer variable, then point the pointer to an array. For example:
- Declare an integer array named `arr`.
Declare a pointer variable named `ptr` that points to an integer.
Assign the pointer `ptr` to point to the array `arr`. - This defines a pointer ptr that points to an array of integers, allowing access to the array elements through ptr.
- By using an array of pointers, you can declare an array where each element is of pointer type. For example:
- Declare an array of pointers in C++.
- This defines a pointer array called ptrArr, where each pointer element can be accessed using ptrArr[i], and each pointer can point to different variables or arrays.
It’s important to note that pointers and arrays are different concepts, but in many cases they can be converted and used interchangeably.