Characters of C.

In C, characters can be grouped into letters, digits, white spaces, special characters, punctuation marks, and escape sequences. In this post, we will see in which cases each of them is used and which are the characters that make them up.
Letters, digits, and underscore
These characters are used for the definition of identifiers (variables, function names, etc.) and are the following:
- Uppercase English alphabet letters
- Lowercase English alphabet letters
- Decimal digits
- Underscore character ("_")
White spaces
White space characters are traditionally characters that exist in a file but are not visible in the print format. The C language uses white spaces to separate consecutive identifiers, format strings, and other special situations. The following characters are treated as white spaces:
- Space character
- Horizontal tab (ASCII 09 or \t)
- Vertical tab (ASCII 11)
- Form feed (ASCII 12)
- Newline (ASCII 10 or \n, ASCII 13 or \r, or CRLF \r\n)
- Comments (see examples below)
Comments
The text enclosed as a comment has no effect on the execution of a program in C. The purpose of comments is to explain the code and make it more understandable to the programmer. Currently, there are different styles of comments that we will see below:
/* Traditional C-style comment */
// C++ style comment
C-style comments are multiline.
/* Multiline
comment */
To show that comments are also white spaces, it is enough to observe the following valid code in C.
int/* comment */foo;
It could be thought that by removing the comment, it would not be possible to differentiate the type of variable from its name, but in reality, as it is white space, C understands perfectly that there is a space between the reserved word and the identifier.
Special characters and punctuation marks
This group of characters is used in different ways. For example, they can indicate that an identifier is a function or an array, an arithmetic, logical, relational operation, etc.
, . ; : ? ' " ( ) [ ] { }
< ! | / \ ~ + # % & ^
* - = >
End of file
The end of file is represented by the following sequence of characters.
- CTRL+Z (Windows)
- CTRL+D (UNIX)
Escape sequences
Escape sequences can represent any of the characters mentioned above. An escape sequence consists of the character \
followed by a letter or combination of digits. They are generally used to indicate a new line, tab stops or non-printable characters.
Sequence | Name |
---|---|
\n |
Go to the beginning of the next line |
\t |
Horizontal tab |
\v |
Vertical tab (print only) |
\b |
Backspace |
\r |
Carriage return without line advance |
\f |
Page feed (print only) |
\a |
Alert or beep |
\' |
Single quote |
\" |
Double quote |
\? |
Question mark |
\\ |
Backslash |
\ddd |
ASCII character. Octal notation (digits from 0 to 7) |
\xdd |
ASCII character. Hexadecimal notation (d is a digit or letter from A to F) |
\udddd |
Unicode character (Also \udddddddd ) |