Data Types continued. . .

The Single Character Type char

A char variable can be used to store a single character. A character constant is formed by enclosing the character within a pair of single quotation marks. So ‘a’, ‘;’, and ‘0’ are all valid examples of character constants. Do not confuse a character constant, which is a single character enclosed in single quotes, with a character string, which is any number of characters enclosed in double quotes.

The format characters %c can be used in a printf call to display the value of a char variable at the terminal.

Special Escape Sequences Character Meaning
\a Audible alert
\b Backspace
\f Form feed
\n Newline
\r Carriage return
\t Horizontal tab
\v Vertical tab
\\ Backslash
\” Double quote
\’ Single quote
\? Question mark
\unnnn Universal character name
\Unnnnnnnn Universal character name
\xnn Hexadecimal character value

 

The Boolean Data Type _Bool

A _Bool variable is defined to store just the values 0 and 1. The amount of memory is used is one byte. _Bool variables are used to indicate a Boolean condition. For example, a _Bool variable may be used to indicate whether the file open is successful or not.

Generally 0 is used to indicate a false value, and 1 indicates a true value. The standard header file <stdbool.h> defines the _Bool as bool, 0 as false and 1 as true.

You may also like...