Pointers can be used to handle array values in C programming. When an array is declared, a memory block is allocated to store the values of the array. The memory address of the first element of the array is also stored. This address is also known as the base address of the array.
A pointer variable can be used to store the base address of the array. Using pointer arithmetic, we can move through the memory locations of the array and access the values stored at those locations.
Here is an example of how pointers can be used to handle array values in C:
This program demonstrates how to use pointers to handle array values in C. It also demonstrates how to use the sizeof operator to find the size of a variable or array in bytes and how to use the printf function to output the values stored in a pointer variable and the memory location it points to.
#include<stdio.h> int main() { int a[]={10,20,30,40,50}; int *p; //{10, 20, 30, 40, 50} //{6356712,6356716,6356720,6356724,6356728} p=&a; printf("\nSize of integer : %d",sizeof(int)); //4 printf("\nSize of a : %d",sizeof(a)); //20 printf("\nLength of a : %d",sizeof(a)/sizeof(int));//5 printf("\nAddress of A : %d",&a);//6356712 printf("\nValue of P : %d",p);//6356712 p++; printf("\nValue of P : %d",p);//6356716 printf("\nValue of *P : %d",*p);//20 printf("\nValue of *++P : %d",*++p);//30 printf("\nValue of ++*P : %d",++*p);//31 return 0; }To download raw file Click Here
Size of integer : 4 Size of a : 20 Length of a : 5 Address of A : 6356712 Value of P : 6356712 Value of P : 6356716 Value of *P : 20 Value of *++P : 30 Value of ++*P : 31
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions