Loading...
C Keywords & Identifiers

C Keywords & Identifiers

In this tutorial, you will learn about Character set, Keywords, Escape sequence characters and identifiers in C programming. We will also learn about rules for naming identifiers.


Character set

A character set is a set of uppercase and lowercase alphabets, digits, whitespaces and some special characters that are valid in C language.

Alphabets

Uppercase: A B C ................................... X Y Z
Lowercase: a b c ...................................... x y z

Digits

0 1 2 3 4 5 6 7 8 9

Special Characters

There are 29 special characters in C language.

, . ; : #
" ! | ~ >
> _ $ ( )
% ? & ^ *
- + [ ] {
} / \ '

White space Characters

Blank space, newline, carriage return, horizontal tab, vertical tab and form feed.


Escape Sequence Characters

Escape sequence characters are used to perform special tasks to manage the C program. They are also known as backslash character constants.

Character Escape Sequence ASCII value
bell (alert) \a 007
backspace \b 008
horizontal tab \t 009
the new line (line feed) \n 010
vertical tab \v 011
form feed \f 012
null \0 000
a quotation mark(") \" 034
carriage return \r 013
apostrophe(') \' 039
a question mark(?) \? 063
backslash(\b) \\ 092
octal number \o0 Eg., \005, \123, \177
hexadecimal number \xhh Eg., \x5, \x7f

Keywords

Keywords are predefined, reserved words in C language that have special meanings to the compiler. We cannot use it as an identifier (variable name, constant name, etc). Keywords are part of the syntax. There are only 32 reserved words (keywords) in the C language.. For example:

Keywords in C Language
auto break case char const
continue default do double else
enum extern float for goto
if int long register return
short signed sizeof static struct
switch typedef union unsigned void
volatile while

Example :

int marks;

In the above example, int is a keyword that indicates marks is a int (integer) type variable .

Note : C is a case sensitive language and all keywords must be written in lowercase. So, we don't use keywords as identifiers.

To know more about all these keywords click - List of all keywords in C programming.


Identifiers

Identifier is the user-defined word used to represent programming entities such as variables, functions, structures, unions etc.

Identifier are used to identify an entity during the execution of the program. Identifiers must be unique.

Example :

int marks;
float percentage;

Here, marks and percentage are identifiers.

Also remember, identifier names must be different from keywords. You cannot use int and float  as an identifier because int and float are keywords.


Rules for naming identifiers

  1. A identifier can only have letters (both uppercase and lowercase letters), digits and underscores.
  2. The first character of an identifier can only contain a letter (both uppercase and lowercase) or an underscore(_).
  3. We cannot use keywords like float, for, while etc. as identifiers.
  4. Indentifiers are case-sensitive in C. Example - name and Name are two different identifiers in C.
  5. We cannot use special characters like semicolon, period, whitespaces, comma in or as identifiers except underscore (_).

Note : Always use meaningful names for identifiers that make sense to easily understand and modify.


Next Tutorial

We hope that this tutorial helped you develop better understanding of the concept of Keywords & Identifiers in C.

Keep Learning : )

In the next tutorial, you'll learn about C Variables & Literals.

- Related Topics