Back to: C Programming for Beginners
In this lesson, we will talk about allowed characters, numbers, special symbols, keywords and identifiers in C Programming.
Table of Contents
Character Set in C Programming
C supports a wide range of Characters (256) which can be used for various purposes. The entire character set is divided into 2 parts i.e. the ASCII characters set and the extended ASCII characters set. An extensive list of all of these is given below:
Alphabets
C supports the English alphabet in both lower and upper cases. We should also keep in mind that C is a case sensitive language. This means that "a"
and "A"
are not the same and will be treated differently by the C compiler.
Supported Alphabets in C Language |
---|
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z |
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z |
Numbers
Supported Numbers in C Language |
---|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9 |
Special Symbols
The below list shows the special symbols used extensively in the C language:
Symbol | Name | Use |
---|---|---|
+ | Plus Sign | Used for Arithmetic Operations, Increment Operator |
- | Minus Sign | Used for Arithmetic Operations, Decrement Operator |
* | Multiplication Sign | Used for Arithmetic Operations, Pointers |
/ | Division Sign | Used for Arithmetic Operations |
% | Percentage / Modulus | Used for Arithmetic Operations |
() | Parenthesis | Used in Function Declarations |
{} | Curly Braces | Used in Function/Structure Body |
[] | Square Brackets | Used in Arrays |
= | Equal To Sign | Used for Arithmetic Operations, Assignment Operator |
, | Comma | Used during Multiple Declarations |
; | Semicolon | Used to Terminate Statements |
: | Colon | Used in Bit-Fields |
' ' | Single Quotes | Used in Character Variable Declaration |
" " | Double Quoted | Used in String Declaration |
? | Question Mark | Used in Ternary Operator |
. | Period / Dot | Used in Member Selection via Object Name |
# | Hash Sign | Used in Preprocessor Directive Declaration |
^ | Caret Sign | Used for Arithmetic and Logical Operations |
~ | Tilde Sign | Used for Logical Operations |
! | Exclamation Mark | Used for Logical Operations |
& | Ampersand Sign | Used for Logical Operations |
| | Pipe Sign | Used for Logical Operations |
Escape Sequences in C Programming
Escape Sequences are characters that do not fall directly into the 256 Character set, supported by C. They do not represent themselves when used inside a string and are difficult or impossible to be represented directly.[1] What this means is these special characters can’t be printed directly using the keyboard. An Escape Sequence always starts with the backslash character \
followed by a particular escape character. The below table gives a detailed list of all Escape Sequences supported in the C language:
Escape Sequence | Name | Use |
---|---|---|
\n | Newline | Used to move the cursor to the beginning of a new line |
\t | Tab | Used to move the cursor to the next Tab stop |
\b | Backspace | Used to move the cursor back by one space on the current line |
\r | Carriage Return | Used to move the cursor to the beginning of the current line |
\a | Bell(alert) | Used to produce a beep sound from the system |
\\ | Backslash | Used to print the Backslash (\ ) character |
\0 | Null | Denotes a null character |
\' | Single Quote | Used to print the Single Quote (' ) character |
\" | Double Quote | Used to print the Double Quote (" ) character |
Newline (\n
), Tab (\t
), Backspace (\b
) and Carriage Return(\r
) are also known as Whitespace characters.
Keywords and Identifiers in C Programming
Keywords
Keywords are reserved words that have special meaning to the C compiler. They are used in the C language for denoting something specific and can not be declared as Identifiers. In C, Keywords are written in lowercase. Originally C had only 32 Keywords but they have been increased with newer C standards.[2]
auto | extern | short | while |
break | float | signed | _Alignas 2, a |
case | for | sizeof | _Alignof 2, a |
char | goto | static | _Atomic 2, b |
const | if | struct | _Bool 1, a |
continue | inline | switch | _Complex 1, b |
default | int | typedef | _Generic 2, a |
do | long | union | _Imaginary 1, b |
double | register | unsigned | _Noreturn 2, a |
else | restrict | void | _Static_assert 2, a |
enum | return | volatile | _Thread_local 2, b |
2 Keyword introduced in ISO C11.
a Starting in Visual Studio 2019 version 16.8, these keywords are supported in code compiled as C when the
/std:c11
or /std:c17
compiler options are specified.b Starting in Visual Studio 2019 version 16.8, these keywords are recognized but not supported by the compiler in code compiled as C when the
/std:c11
 or /std:c17
 compiler options are specified.Identifiers
Identifiers are user-given names to various C entities such as variables, functions, array, structure, symbolic constant etc. Identifiers are used extensively by the Programmer to access various entities of the C language. There are strict rules in C for naming these entities. These rules have been mentioned below:[3]
- Identifiers can only have alphanumeric characters (
a-z
,A-Z
,0-9
) and underscore (_
) only in their name. - Identifier names must be unique. No two Identifiers in the same program can have the same name.
- The first character of an Identifier must be an alphabet or the underscore (
_
). Numbers are not allowed in the first character. - The Identifier name can’t be the same as that of a Keyword.
- Identifiers are case-sensitive.
- There must not be white spaces inside the Identifier name.
Valid Examples of Identifier Names
- Identifiers with only alphabets:
var
,Var
,VAR
. - Identifiers with alphabets and numbers:
var1
,VAR123
,V123ar
. - Identifiers with underscore:
var_
,Var_123
,_VAR
,var_VAR
.
Invalid Examples of Identifier Names
- Identifiers starting with Numbers:
1Var
,123VAR
. - Use of space between alphabets and numbers:
var 123
. - Use of special symbols:
var#
,Var@123
.
References
Best C Programming Books
List of C Programming books curated for beginners as well as experienced programmers.
Sharing is Caring
If you liked this post, then feel free to share it with your loved ones!