Thread: \'a\' and 'a'

  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
    casual coder spaghetticode's Avatar
    Join Date
    Jan 2011
    Location
    Hesse, Germany
    Posts
    259
    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
    733
    Both are valid, the latter is clearer. Use the former or the latter, but do not mix them.

Popular pages Recent additions subscribe to a feed