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

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    The Programming Dutchman
    Join Date
    Jan 2008
    Posts
    55

    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.
    Last edited by Jelte; 08-04-2009 at 12:15 PM.
    The Programming Dutchman

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing unique numbers to an array
    By yardy in forum C Programming
    Replies: 6
    Last Post: 12-27-2006, 09:15 PM
  2. Printing numbers in hex format
    By miclus in forum C++ Programming
    Replies: 7
    Last Post: 01-29-2005, 07:04 AM
  3. Program that prints numbers in columns
    By rayrayj52 in forum C++ Programming
    Replies: 12
    Last Post: 09-20-2004, 02:43 PM
  4. converting hex to dec
    By jibbles in forum C Programming
    Replies: 20
    Last Post: 08-07-2004, 11:40 PM
  5. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM