pointer arithmetic with array
#include <stdio.h>
int main()
{
int aray[3]={2,5,10};
// three ways to access pointer value
printf("value of 1st element: %d\n",aray[0]);
printf("value of 1st element: %d\n",*aray);
printf("value of 1st element: %d\n\n",*(&aray[0]));
// two ways to access pointer address
printf("address of 1st element: %d\n",aray);
printf("address of 1st element: %d\n\n",&aray[0]);
// two ways to access pointer address
printf("address of 2nd element: %d\n",aray+1);//this will not add 1 instead it will add 1 data type size and becomes 2nd elements address
printf("address of 2nd element: %d\n\n",&aray[1]);
printf("before addition: %d\n",aray);
printf("after addition it becomes address of 3rd element: %d\n",aray+2);
printf("address of 3rd element: %d",&aray[2]);
return 0;
}
Comments
Post a Comment