For the for loop below each outputs 4,3,2,1,0 - how does this work exactly?
the first loop:
for (p=a+4, i=0; i<=4; i++) PRD(p[-i]);
is this just that we start at p[4] and keep going down until i = 4 which leaves us at p[0]? can someone please walk me through how it is being interpreted?
the second loop:
for (p=a+4; p>=a; p--) PRD(a[p-a]);
the first pass of this look p = 4, a = 0? is output here "a[4-0,3-0,2-0,1-0,0-0]"?
Code:#define PRD(a) printf("%d", (a) )#define NL printf("\n"); // Create and initialse array int a[]={0, 1, 2, 3, 4}; int main() { int i; int* p; for (p=a+4, i=0; i<=4; i++) PRD(p[-i]); for (p=a+4; p>=a; p--) PRD(a[p-a]); }



3Likes
LinkBack URL
About LinkBacks



