Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > sizeof character constants in C++

Reply
Thread Tools

sizeof character constants in C++

 
 
Kavya
Guest
Posts: n/a
 
      11-08-2006
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?

 
Reply With Quote
 
 
 
 
Pete Becker
Guest
Posts: n/a
 
      11-08-2006
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.
 
Reply With Quote
 
 
 
 
miteshrajpandey@yahoo.com
Guest
Posts: n/a
 
      11-08-2006
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sizeof(EmptyStruct) in C and C++ (was: Base {}; sizeof(Base) == 1?) Alex Vinokur C Programming 7 08-14-2006 04:57 PM
sizeof( int ) != sizeof( void * ) blufox C Programming 2 05-22-2006 03:25 PM
#define ARR_SIZE sizeof(arr)/sizeof(arr[0]) Vinu C Programming 13 05-12-2005 06:00 PM
sizeof(enum) == sizeof(int) ??? Derek C++ 7 10-14-2004 05:11 PM
sizeof(str) or sizeof(str) - 1 ? Trevor C Programming 9 04-10-2004 05:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57