sizeof character constants in C++

Discussion in 'C++' started by Kavya, Nov 8, 2006.

  1. Kavya

    Kavya Guest

    In C, the character constants are of type int but in C++ character
    constant are of type char. Why is there an incompatibilty here when C++
    was designed to be a lot compatible to C. Shouldn't such small things
    be same in both the languages?
     
    Kavya, Nov 8, 2006
    #1
    1. Advertising

  2. Kavya

    Pete Becker Guest

    Kavya wrote:
    > In C, the character constants are of type int but in C++ character
    > constant are of type char. Why is there an incompatibilty here
    >


    Briefly, function overloading.

    std::cout << 'a' << 3 << '\n';

    If char constants had type int, all three insertions would be inserting
    int values.

    --

    -- Pete

    Author of "The Standard C++ Library Extensions: a Tutorial and
    Reference." For more information about this book, see
    www.petebecker.com/tr1book.
     
    Pete Becker, Nov 8, 2006
    #2
    1. Advertising

  3. Kavya

    Guest

    char variables in C and C++ are compatible (in fact they are same). We
    do not use literals directly but only through variables. So i think
    there is no requirement for the literals to be compatible between C and
    C++. Also literals are usually declared in const memory area.
     
    , Nov 8, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Derek
    Replies:
    7
    Views:
    24,340
    Ron Natalie
    Oct 14, 2004
  2. Trevor

    sizeof(str) or sizeof(str) - 1 ?

    Trevor, Apr 3, 2004, in forum: C Programming
    Replies:
    9
    Views:
    635
    CBFalconer
    Apr 10, 2004
  3. Vinu
    Replies:
    13
    Views:
    1,432
    Lawrence Kirby
    May 12, 2005
  4. blufox

    sizeof( int ) != sizeof( void * )

    blufox, May 22, 2006, in forum: C Programming
    Replies:
    2
    Views:
    560
    Joe Smith
    May 22, 2006
  5. Alex Vinokur
    Replies:
    7
    Views:
    498
    Clark S. Cox III
    Aug 14, 2006
Loading...

Share This Page