You can also do it in this way:
// code from first for loop
// Print the array
for (; p <= &charr[4]; ++p) {
printf("Array elements in the normal order: %d\n", *p);
}
putchar('\n');
// Print the reverse array
for (--p; p >= &charr[0]; p--) {
printf("Array elements in the reverse order: %d\n", *p);
}
putchar('\n');
// print the sum of array
for (++p; p <= &charr[4]; p++) {
sum+= *p;
}
printf("Sum of the array is %d\n", sum);
You declared and initialized p as int* to &charr[0] in the statement, int* p = charr;. So you can omit the initialization part of the 1st for loop.
When 1st for loop exits, p points to the memory address one next to &charr[4] so in the initialization part of the 2nd for loop the expression --p makes p to point to &charr[4].
Finally, when 2nd loop exits, p points to 1 less than the &charr[0], so in the initialization part of the 3rd for loop, I did ++p to make p point to &charr[0].
In this way you can also achieve what the sum you expected, but it is an alternative not the best way. Because everytime you need to keep track of the memory address to which p points to.
Best way is:
// 1st loop
for(p = &charr[0]; p <= &charr[4]; p++)
// printing statement
// 2nd loop
for(p = &charr[4]; p >= &charr[0]; p--)
// reverse printing statement
//3rd loop
for(p = &charr[0]; p <= &charr[4]; p++)
// sum statement
*pin your loop?