output ?

What is the output 6 or 5 and why ?
1
2
3
4
int number = 6;
int x = 0;
x = number--;
cout << x << endl;


so the answer is 6 yes ? I mean the operators will only take affect if it was placed before number. take this for example :

1
2
int number = 6;
cout << number++ << endl;


answer would still be 6
no replies ? is it that hard ? i don't have a visual studio at home. But I have noticed majority programmers are so egotistical
1
2
3
4
5
6
7
8
int Number = 6;
int x = Number--;
// At this point Number is 5, and x is 6.


int Number = 6;
int x = --Number;
// At this point Number is 5, and x is 5. 


The main issue why I couldn't find myself to reply sooner is:
1. Timing
2. Topic name

Be a bit more explicit, the issue in your program is not the output itself, but is the Increment/Decrement operator.
Last edited on
Read the stickies and do not post twice kittycat
http://www.cplusplus.com/forum/beginner/102308/
@Kittycat
Kittycat wrote:
no replies ? is it that hard ?

How do you expect an answer with an attitude like that

Read this
http://www.cplusplus.com/forum/beginner/1/
http://www.cplusplus.com/forum/beginner/1/
http://www.cplusplus.com/forum/beginner/1/
http://www.cplusplus.com/forum/beginner/1/
Last edited on
Topic archived. No new replies allowed.