RAD Studio |  |

Character Constants
See Also
Collapse All

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.

- Three char types
- Escape sequences
- Wide-character and multi-character constants

Note: To compare sizes of character types, compile this as a C program and then as a C++ program.
Copy Code

    #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) );
    }

Note: Sizes are in bytes.

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

See Also

Constants

Integer Constants

Integer Constant Without L Or U

Floating Point Constants

The Three Char Types

Escape Sequences

Wide-character And Multi-character Constants

String Constants

Enumeration Constants

Constants And Internal Representation

Internal Representation Of Numerical Types

Constant Expressions

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!