char

Specifier Description
char Use to declare arrays of characters, pointers to characters, and arrays of pointers to characters.
signed char, unsigned char Use to declare numeric variables that occupy a single byte.

To declare a data object having a character type, use the char type specifier. The char specifier has the form:

The declarator for a simple character declaration is an identifier. You can initialize a simple character with a character constant or with an expression that evaluates to an integer.

The C language has three character data types: char, signed char, and unsigned char. These data types are not compatible with each other, but each provides enough storage to hold any member of the ASCII character set. The amount of storage allocated for a char is implementation-dependent. AIX uses 8 bits to represent a character, as defined by the CHAR_BIT macro in the <limits.h> header.

The default character type behaves like an unsigned char. To change this default, use #pragma chars or the chars compiler option on AIX or the /J compiler option on Intel.

If it does not matter whether a char data object is signed or unsigned, you can declare the object as having the data type char. Otherwise, explicitly declare the object as signed char or unsigned char. When a char (signed or unsigned) is widened to an int, its value is preserved.

For the purposes of distinguishing overloaded functions, a C++ char is a distinct type from signed char and unsigned char.

The following example defines the identifier end_of_string as a constant object of type char having the initial value \0 (the null character):

const char end_of_string = '\0';

The following example defines the unsigned char variable switches as having the initial value 3:

unsigned char switches = 3;

The following example defines string_pointer as a pointer to a character:

char *string_pointer;

The following example defines name as a pointer to a character. After initialization, name points to the first letter in the character string "Johnny":

char *name = "Johnny";

The following example defines a one-dimensional array of pointers to characters. The array has three elements. Initially they are a pointer to the string "Venus", a pointer to "Jupiter", and a pointer to "Saturn":

static char *planets[ ] = { "Venus", "Jupiter", "Saturn" };


Lexical Elements of C - Character Constants


Array Type
Pointer Type