5
Contributors
6
Replies
34
Views
3 Years
Discussion Span
Last Post by Ancient Dragon
1

I'm glad that I have the knowledge to help you here ,
++ and -- add +1 or -1 to the variable

for example x++ is equal to x=x+1 and x-- is equal to x=x-1

Votes + Comments
0

what can(++)and(--) do in c++ source code?

++ increase the variable value by 1.

int x=0;
cout<<x<<endl;
x++;
cout<<x;

output:

0
1

lets see more about ++.

x++(postfix)
++x(prefix)

there is an important difference between postfix and prefix.

int x,y=10;
x=++y;

output:

x=11
y=11

int x,y=10;
x=y++;

output:

x=10
y=11

now i hope you can adjust with --
for more information read this tutorial

Edited by Learner010

0

But beware of unconventional constructs like ++x-- or y = ++x - x--; Such constructs have undefined behavior, the compiler is free to produce any results it wants.

Edited by Ancient Dragon

0

the compiler is free to produce any results it wants.

i check these expression in different environment and they produce different result. i think these expression are compiler dependent.

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.