stupid question of the day

This is a discussion on stupid question of the day within the C++ Programming forums, part of the General Programming Boards category; hi, What is the value of the following expression: 'g'-'a'+'A' thanks...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    7

    Question stupid question of the day

    hi,

    What is the value of the following expression:


    'g'-'a'+'A'


    thanks

  2. #2
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    1) dont you have a compiler to test it
    2) learn the ASCII table or have an ASCII table in handy

    well once again i am bored

    Code:
    char x = 'g'-'a'+'A';
    
    cout << x << endl;
    //hmm it should output 'G' or 71 in ASCII
    nextus, the samurai warrior

  3. #3
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    You shouldn't need an ascii table.

    All lowercase letters are consecutive and all uppercase letters are consecutive so a lower case letter minus lowercase a will give you the offset in the alphabet (a is 0, b is 1 ... z is 25). So adding the offset to capital A will give you the capital version of the letter.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Question Probably
    By Kyrin in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 01:51 AM
  2. Replies: 7
    Last Post: 11-04-2005, 12:17 AM
  3. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 12:43 PM
  4. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 08:22 PM
  5. Stupid question: What does Debugger do?
    By napkin111 in forum C++ Programming
    Replies: 6
    Last Post: 05-02-2002, 11:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21