In this lesson, we will talk about allowed characters, numbers, special symbols, keywords and identifiers in C Programming.

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:

SymbolNameUse
+Plus SignUsed for Arithmetic Operations, Increment Operator
-Minus SignUsed for Arithmetic Operations, Decrement Operator
*Multiplication SignUsed for Arithmetic Operations, Pointers
/Division SignUsed for Arithmetic Operations
%Percentage / ModulusUsed for Arithmetic Operations
()ParenthesisUsed in Function Declarations
{}Curly BracesUsed in Function/Structure Body
[]Square BracketsUsed in Arrays
=Equal To SignUsed for Arithmetic Operations, Assignment Operator
,CommaUsed during Multiple Declarations
;SemicolonUsed to Terminate Statements
:ColonUsed in Bit-Fields
' 'Single QuotesUsed in Character Variable Declaration
" "Double QuotedUsed in String Declaration
?Question MarkUsed in Ternary Operator
.Period / DotUsed in Member Selection via Object Name
#Hash SignUsed in Preprocessor Directive Declaration
^Caret SignUsed for Arithmetic and Logical Operations
~Tilde SignUsed for Logical Operations
!Exclamation MarkUsed for Logical Operations
&Ampersand SignUsed for Logical Operations
|Pipe SignUsed 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 SequenceNameUse
\nNewlineUsed to move the cursor to the beginning of a new line
\tTabUsed to move the cursor to the next Tab stop
\bBackspaceUsed to move the cursor back by one space on the current line
\rCarriage ReturnUsed to move the cursor to the beginning of the current line
\aBell(alert)Used to produce a beep sound from the system
\\BackslashUsed to print the Backslash (\) character
\0NullDenotes a null character
\'Single QuoteUsed to print the Single Quote (') character
\"Double QuoteUsed 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]

autoexternshortwhile
breakfloatsigned_Alignas2, a
caseforsizeof_Alignof2, a
chargotostatic_Atomic2, b
constifstruct_Bool1, a
continueinlineswitch_Complex1, b
defaultinttypedef_Generic2, a
dolongunion_Imaginary1, b
doubleregisterunsigned_Noreturn2, a
elserestrictvoid_Static_assert2, a
enumreturnvolatile_Thread_local2, b
1 Keyword introduced in ISO C99.
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

  1. Escape Sequences in C (GeekForGeeks)
  2. C standard keywords (Microsoft Docs)
  3. C Identifiers (W3Schools)

Best C Programming Books

List of C Programming books curated for beginners as well as experienced programmers.

C Programming Books

Sharing is Caring

If you liked this post, then feel free to share it with your loved ones!

Leave a Reply