Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

explain the c++ statement cout<<++*ptr++;

0 votes
asked Dec 6, 2019 by anonymous

1 Answer

0 votes
answered Dec 11, 2019 by gameforcer (2,990 points)
edited Dec 13, 2019 by gameforcer

Let's split it:

1. cout<<++*ptr++;

These two plus signs are called preincrementation. 'Incrementation;' means adding 1 to the value of something, "incrementing" it. 'Pre' means that it happens before the operation. Combining these two we can conclude that it first adds 1 to the value and after then it is printed out in console.

2. cout<<++*ptr++;

It is counterpart of preincrementation, namely postincrementation. Post signifies that this time it is operation that goes first and only then the value is increased by 1. So in this case firstly we print out the value and secondly we add 1 to it.

2. cout<<++*ptr++;

If you don't know by now, in programming languages there is a concept of 'pointers'. They are a special type of data that is used to store memory address of other types of data (such as numbers, strings, etc.). In this case scenario *ptr means the value pointer is pointing to.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...