Best C Programming code for representing array using pointer(January,2021)
Introduction :
In C programming we use array for storing homogeneous data. Array is static in nature. We all know these things but the point of discussion is “How array can be represented by pointer?”
As we know the address of the first element of an array is base address. We can use this address for accessing other element, because array is continuous memory allocation.
According to pointer variable concept, we can use pointer variable to store the address of another variable. As I have earlier said that address of the first element of an array is the base address of the array. So, we can store that address into one pointer variable and we can access that pointer variable to traverse the array. In this code I have shown the process of storing base address of an array into one pointer variable in a very easier way.
I hope you will be able to understand the code. If you are finding any difficulties please put your comment and you also can send me email. My email id is : creativeresource2020@gmail.com
#include<stdio.h>
int main()
{
int ar[10],*ptr,m,i;
ptr=&ar[0];
printf("Enter the number of elements : ");
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%d",(ptr+i));
}
printf("Values are : ");
for(i=0;i<m;i++)
{
printf("%d,",*(ptr+i));
}
}