# Thread: HEX-numbers after incrementation x in for-loop.

1. ## HEX-numbers after incrementation x in for-loop.

SORRY FOR THE DOUBLE POST IN THE FORUM, PLEASE ADMIN REMOVE ONE OF THEM, THANKS

Hello Folks,

I made a little simple program to practice C++, My goals was too see how the two different methods of incrementation (example: x++ and ++x) would be handled in a for-loop.

this is the program:

Code:
```#include <iostream>

using namespace std;

void ForIncrementFront()
{
for(int x = 0; x < 10; ++x)
{
cout << x << "\t";
}
}

void ForIncrementBehind()
{
for(int x = 0; x < 10; x++)
{
cout << x << "\t";
}
}

int main()
{
cout << "Function: ForIncrementFront  (++x)\n";
ForIncrementFront();
cout << "Function: ForIncrementBehind (x++)\n";
ForIncrementBehind();

return 0;
}```
this was my output:
Code:
```Function: ForIncrementFront (++x):
0 1 2 3 4 5 6 7 8 9 F
Function: ForIncrementBehind (x++):
0 1 2 3 4 5 6 7 8 9```

The output of function ForIncrementFont surprised me a little bit because 10 is printed as F and not as 10. what I would like to know is why F instead of 10?, is this a proof of the fact that the PC "speaks" only Hexadecimal and binary? if this is true, why is the output of the code below: 10.

Code:
`cout << 9+1;`

I hope you understand my question. Sorry if my English grammar is bad, IŽam dutch.

2. I cannot duplicate your output, and indeed I do not expect such output. I expect the two functions to print the exact same output, and they do so when I tested your program.

3. @laserlight hey thanks for your quick message .

maybe some specs of my Dev Software helps.?

OS: Ubuntu 9.04.
Dev prog: Code::blocks 8.02.
Compiler: GNU GCC Compiler .

Edit:

i am not surprised about the output of the functions, this is normal. But i am surprised about 10 is printed as F in situation 1, and in situation 2 as 10.

4. Did you copy and paste the code that you actually compiled?

5. i am not surprised about the output of the functions, this is normal. But i am surprised about 10 is printed as F in situation 1, and in situation 2 as 10.
10 is not printed as F. Your loop goes from 0-9, so 10 will never get printed at all.

My best guess is there is an issue with your terminal that is word wrapping the output text. Your correct output should be:
Code:
```Function: ForIncrementFront (++x):
0 1 2 3 4 5 6 7 8 9 Function: ForIncrementBehind (x++):
0 1 2 3 4 5 6 7 8 9```
Note that there is NOT a newline between the 9 and the "Function: ForIncrementBehind" text.

6. @laserlight: no this is my own program.

@bithub:

i think 10 should be printed because there is a difference between X++ and ++X. i can show you that by this program:

Code:
```#include <iostream>

using namespace std;

int main()
{
unsigned short numberx = 0;
unsigned short numbery = 0;

cout << "incrementie-front\t"  << ++numberx   << endl;
cout << "incrementie-behind\t" << numbery++   << endl;
cout << endl;
cout << "numberx:\t" << numberx << endl;
cout << "numbery:\t" << numbery << endl;

return 0;
}```
As you can see there is a moment when numberx and numbery are different, because numbery get updated AFTER it is printed on the screen. i think this should be the same in a for-loop. and so 10/F should be printed on the screen.

please correct me if i am wrong...

Thanks for help.

Jelte.

7. i think 10 should be printed because there is a difference between X++ and ++X. i can show you that by this program:
No, that's not correct. It doesn't matter if you pre-increment or post-increment the value in the for loop because its return value is not evaluated. In other words, you are not assigning it to anything.

It basically looks like:
Code:
``` for(int x = 0; x < 10; ++x)
cout << x << endl;
// is the same as...
int x = 0;
while(x < 10)
{
cout << x << endl;
++x; // notice that it doesn't matter if you have ++x or x++
}```

8. @bithub: ok. thanks for you correction and your clear explanation.

also you where right about i realised that F is is not 10 in HEX. i do not know why i thought 10 in HEX was F instead of A :P

so, what else could F be? i do not use the ubuntu terminal but the console of code::blocks.

9. Originally Posted by Jelte
so, what else could F be? i do not use the ubuntu terminal but the console of code::blocks.
Then this is what you see (and notice the complete absence of an extra F):

10. Can you please post your ACTUAL code? I know that this cannot possibly be your code, because this line:

Code:
`    cout << "Function: ForIncrementFront  (++x)\n";`
Cannot produce this output:

Code:
`Function: ForIncrementFront (++x):`
Since there is no ':' character in the string. Post the ACTUAL code and maybe we can avoid wasting our time

11. Originally Posted by Jelte
no this is my own program.
What I meant is whether you copied and pasted the code from your text editor as opposed to rewriting it out in your post (i.e, what brewbuck restated about posting your actual code). Anyway, I think bithub's explanation is as likely as a stray character in the output that I had in mind: the console window opened by Code::Blocks can have the same effect that bithub described. You just need to be careful in interpreting the output, but perhaps it would be simpler to just introduce a new line:
Code:
```void ForIncrementFront()
{
for(int x = 0; x < 10; ++x)
{
cout << x << ' ';
}
cout << '\n';
}

void ForIncrementBehind()
{
for(int x = 0; x < 10; x++)
{
cout << x << ' ';
}
cout << '\n';
}```

12. Owh.., i got it and it is sooo stupid , Sorry everybody for this ... not existing problem post (it is a little bit funny now). see attached image.

you all may start Rolling On Floor Laughing :\$

Greeting

Jelte,