By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,412 Members | 978 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,412 IT Pros & Developers. It's quick & easy.

sizeof character constants in C++

P: n/a
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?

Nov 8 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
Nov 8 '06 #2

P: n/a
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 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.