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.
![Pointers and Arrays in C Programming Example](https://learningmonkey.in/wp-content/uploads/2021/07/Pointers-and-Arrays-in-C-Programming-Example.png)
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.
![Pointers and Arrays in C Programming First Line](https://learningmonkey.in/wp-content/uploads/2021/07/Pointers-and-Arrays-in-C-Programming-First-Line.png)
A pointer variable p has been created in the second line of code, but the pointer variable has not been assigned.
![Pointers and Arrays in C Programming Second Line](https://learningmonkey.in/wp-content/uploads/2021/07/Pointers-and-Arrays-in-C-Programming-Second-Line.png)
In the third line of code, we assign the starting address of the array’s first element to the pointer variable.
![Pointers and Arrays in C Programming Third Line](https://learningmonkey.in/wp-content/uploads/2021/07/Pointers-and-Arrays-in-C-Programming-Third-Line.png)
In the fourth line of code, we assign five to the array’s first element by using the pointer variable.
![Pointers and Arrays in C Programming Fourth Line](https://learningmonkey.in/wp-content/uploads/2021/07/Pointers-and-Arrays-in-C-Programming-Fourth-Line.png)
In our next class we will try to understand How to access the values of an array using pointer variable.