Help me please! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help me please!

So here is the code #include <iostream> using namespace std; int main() { int Number[]={2,4,8,10}; int *ptr=Number; for(int C=0;C<3;C++) {cout<<*ptr<<"@"; ptr++; } { cout<<endl; for(int C=0;C<4;C++) {(*ptr)*=2; cout<<Number[C]<<"#"; --ptr; }} cout<<endl; return 0; } Please somebody explain me the work of that --p. I understood the p++ for increment but I'm unable to relate the same with --p. When I run it the output comes out to be 2#4#8#16#20# for --p part. Please explain it to me with the help of the given output. Thank you

18th Feb 2020, 1:20 PM
Debasish Sarma
Debasish Sarma - avatar
1 Answer
+ 1
p++ increments at the end of the loop, p-- would decrement at the end of the loop. Placing the -- symbol before p, such as --p, means that before the loop takes place, p is decremented by 1.
12th Mar 2021, 5:23 PM
Zhar
Zhar - avatar