sizeof character constants in C++

K

Kavya

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?
 
P

Pete Becker

Kavya said:
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.
 
M

miteshrajpandey

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top