4
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
1

i cant understand what does ++*++p means???
can u help me

Consider the following code:

#include <iostream>

int main()
{
  int a[5] = {0, 5, 2, 3, 4};
  int *p = a;
  
  ++*++p;
  std::cout << a[1] << std::endl;
  
  return 0;
}
/* Output:
6
*/

Explanation:
The first ++ will increase the value on its right side (*++p).
According to the rules of precedence, ++p will be executed before the pointer is dereferenced, so the pointer (which was pointing to the first element (element 0) of the array) now points to the second element (element 1) of the array, then the pointer is dereferenced.
The value (that we got by dereferencing that pointer) will now be increased by one.

Votes + Comments
Good explanation of ++*++p - I learned something new too :P
0

Chances of getting an answer is even greater if you give your request a meaningful title.

0

Chances of getting an answer is even greater if you give your request a meaningful title.

He couldn't help it, first he hijacked a thread, then a moderator was informed to split this into a new thread, and the thread's title was decided by a moderator.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.