character code points versus plain integers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dorkz
    Banned
    New Member
    • Aug 2007
    • 14

    character code points versus plain integers

    if i do this:

    [CODE=cpp]#include <iostream>

    int main()

    {
    char number1 = '9' , number2 = '1' , answer ;
    answer = '9' + '1'

    cout << answer << endl ;
    cin.get()
    }[/CODE]

    then the result will be: :



    and if i do this :
    [CODE=cpp]
    #include <iostream>

    int main()

    {
    char number1 = 9 , number2 = 1 , answer ;
    answer = 9 + 1

    cout << answer << endl ;
    cin.get()
    }[/CODE]

    whats the result now?
    Last edited by Ganon11; Aug 14 '07, 03:41 PM. Reason: code tags added
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    '1' is just another notation for the Latin 1 (formerly known as ASCII) code for the
    code point 49. '9' has code point value 57. So basically you're adding 49+57.

    kind regards,

    Jos

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Originally posted by JosAH
      '1' is just another notation for the Latin 1 (formerly known as ASCII) code for the
      code point 49. '9' has code point value 57. So basically you're adding 49+57.

      kind regards,

      Jos
      mcfaker, I mean, dorkz, did you try putting it into a compiler?

      And please use code tags in the future.

      Comment

      • dorkz
        Banned
        New Member
        • Aug 2007
        • 14

        #4
        thanks , but you mean that in the first example with the apostrofs, the result will be : 49 + 57 = 106, and 106 is character 'j' ??? do you mean that?

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by dorkz
          thanks , but you mean that in the first example with the apostrofs, the result will be : 49 + 57 = 106, and 106 is character 'j' ??? do you mean that?
          I don't know what the code point value of a lower case 'j' is, but if it is 106, then yes,
          that's what I mean.

          kind regards,

          Jos

          Comment

          • dorkz
            Banned
            New Member
            • Aug 2007
            • 14

            #6
            yes it is 'j'


            but , by the second example , the example without the apostrofs , what is the result of this? 10?

            Comment

            • dorkz
              Banned
              New Member
              • Aug 2007
              • 14

              #7
              hello? coolpeople coming to help me.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by dorkz
                hello? coolpeople coming to help me.
                You do know how to do simple additions do you?

                kind regards,

                Jos

                Comment

                • sicarie
                  Recognized Expert Specialist
                  • Nov 2006
                  • 4677

                  #9
                  Originally posted by JosAH
                  You do know how to do simple additions do you?

                  kind regards,

                  Jos
                  And if you don't want to do addition, see post #3.

                  Comment

                  • dorkz
                    Banned
                    New Member
                    • Aug 2007
                    • 14

                    #10
                    yes i know, but come on answer please, cause ur soo smart,please answer that question. thank you , thank you , thank you

                    Comment

                    • dorkz
                      Banned
                      New Member
                      • Aug 2007
                      • 14

                      #11
                      look 9 + 1 without apostrofs is 10 anyhow?

                      Comment

                      • dorkz
                        Banned
                        New Member
                        • Aug 2007
                        • 14

                        #12
                        ASCII-codes use by char

                        please answer wirhout apostrofs, will it be 10??

                        Comment

                        • sicarie
                          Recognized Expert Specialist
                          • Nov 2006
                          • 4677

                          #13
                          dorkz-

                          Please check your PM's - they are in the top right of the page.

                          Thanks,

                          sicarie

                          Comment

                          • dorkz
                            Banned
                            New Member
                            • Aug 2007
                            • 14

                            #14
                            im in shock! but please answer, then i stop answering?ok?

                            Comment

                            • JosAH
                              Recognized Expert MVP
                              • Mar 2007
                              • 11453

                              #15
                              Originally posted by dorkz
                              im in shock! but please answer, then i stop answering?ok?
                              Everything is answered already. '1'+'9'= 106; 1+9= 10.

                              kind regards,

                              Jos

                              Comment

                              Working...