\'a\' and 'a'

This is a discussion on \'a\' and 'a' within the C++ Programming forums, part of the General Programming Boards category; Hi The following both codes work the same way. But I have seen codes which most of the time use ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    254

    \'a\' and 'a'

    Hi

    The following both codes work the same way. But I have seen codes which most of the time use the first version. What do you have to say on this? Please let me know. Thanks.

    Code:
    if (a == 0)
        {
            cout << "\'a\' shouldn' be zero\n";
            exit(0);
        }
    Code:
    if (a == 0)
        {
            cout << "'a' shouldn' be zero\n";
            exit(0);
        }
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  2. #2
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    My best guess (as a beginner too) would be that you can't just assume your compiler will know the difference between a simple char and a string literal, though 'a' is clearly included in a string literal here.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    671
    Both are valid, the latter is clearer. Use the former or the latter, but do not mix them.
    I never put signature, but I decided to make an exception.

Popular pages Recent additions subscribe to a feed

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