A character constant is one or more characters enclosed in single quotes, such as 'A', '+', or '\n'. In C, single-character constants have data type int. In C++, a character constant has type char. Multicharacter constants in both C and C++ have data type int.
To learn more about character constants, see the following topics.
#include <stdio.h> #define CH 'x' /* A CHARACTER CONSTANT */ void main(void) { char ch = 'x'; /* A char VARIABLE */ printf("\nSizeof int = %d", sizeof(int) ); printf("\nSizeof char = %d", sizeof(char) ); printf("\nSizeof ch = %d", sizeof(ch) ); printf("\nSizeof CH = %d", sizeof(CH) ); printf("\nSizeof wchar_t = %d", sizeof(wchar_t) ); }
Sizes of character types
Output when compiled as C program |
Output when compiled as C++ program |
Sizeof int = 4 |
Sizeof int = 4 |
Sizeof char = 1 |
Sizeof char = 1 |
Sizeof ch = 1 |
Sizeof ch = 1 |
Sizeof CH = 4 |
Sizeof CH = 1 |
Sizeof wchar_t = 2 |
Sizeof wchar_t = 2 |
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|