Introduction
When the pointer is incremented by an increment operator, it is always right incremented. That is, if the pointer points to an integer, the pointer is incremented by 2, and, if it is long, it is incremented by 4.
Program
#includevoid printarr(int a[]); void printdetail(int a[]); void print_usingptr(int a[]); main() { int a[5]; for(int i = 0;i<5;i++) { a[i]=i; } print_usingptr(a); } void printarr(int a[]) { for(int i = 0;i<5;i++) { printf("value in array %d\n",a[i]); } } void printdetail(int a[]) { for(int i = 0;i<5;i++) { printf("value in array %d and address is %8u\n",a[i],&a[i]); } } void print_usingptr(int a[]) { int *b; b=a; for(int i = 0;i<5;i++) { printf("value in array %d and address is %16lu\n",*b,b); b++; // A } }
Explanation
Point to Remember
The increment operator increments the pointer according to the size of the data type.
No comments:
Post a Comment