Pointers and Arrays in C
In this class, we will understand Pointers and Arrays in C.
So far, we have seen how the integer and floating-point variables address can be assigned to pointer variables.
But C provides the facility to assign the address of arrays also.
Pointers and Arrays
To understand this concept, we will use the program shown in the image below.
We will try to visualize every line of code and understand how we can assign an array to a pointer.
In the first line of code, an integer array of five elements has been created.
Assume that each integer occupies two bytes of space.
A pointer variable p has been created in the second line of code, but the pointer variable has not been assigned.
In the third line of code, we assign the starting address of the array’s first element to the pointer variable.
In the fourth line of code, we assign five to the array’s first element by using the pointer variable.
In our next class we will try to understand How to access the values of an array using pointer variable.