It will clear the confusion about the pointer when arises.
Sum clear:
example code:
#include<stdio.h> int main() { int a,b,c; int *pa,*pb,*pc; a=10; b=40; pa=&a; pb=&b; pc=&c; *pc=*pb+*pa; printf("Sum = %d",*pc); return 0; }
Array and Pointer:
#include<stdio.h> int main() { int a[5],i; printf("Enter 5 integer:\n"); for(i=0;i<=4;i++) { scanf("%d",&a[i]); } printf("Array elements are:\n"); for(i=0;i<=4;i++) { printf("array=%d\n pointer=%d\n",a[i],*(a+i)); } return 0; }
Array is nothing but a pointer:
#include<stdio.h> int main() { int a[5],i; printf("Enter 5 integer:\n"); for(i=0;i<=4;i++) { scanf("%d",&a[i]); } printf("Array elements are:\n"); for(i=0;i<=4;i++) { printf("address=%X \n array=%d\n pointer=%d\n",a+i,a[i],*(a+i)); printf("arrayulta=%d\n pointerulta=%d\n",i[a],*(i+a)); } return 0; }
another variable pointer example:
#include<stdio.h> int main() { int a[5],i,*p; printf("Enter 5 integer:\n"); for(i=0;i<=4;i++) { scanf("%d",&a[i]); } printf("Array elements are:\n"); p=a; for(i=0;i<=4;i++) { printf("punga= %d %d %d %d\n",p[i],i[p],*(p+i),*(i+p)); } return 0; }