C Tokens, Keywords & Identifiers: Types & Examples

โšก Smart Summary

Tokens in C are the smallest individual units the compiler reads, and every C program is built from six token types: keywords, identifiers, constants, strings, operators, and special symbols drawn from the C character set.

  • ๐Ÿ”ค Character set: C source uses letters, digits, white spaces, and special characters that combine to form every token and symbol.
  • ๐Ÿงฉ Six token types: The compiler splits a program into keywords, identifiers, constants, strings, operators, and special symbols.
  • ๐Ÿ”‘ Keywords: C reserves 32 lowercase keywords such as int, for, and return, each with a fixed meaning you cannot redefine.
  • ๐Ÿท๏ธ Identifiers: User-defined names for variables and functions must start with a letter or underscore and avoid reserved keywords.
  • ๐Ÿ”ข Constants and strings: Constants hold fixed values, while string literals group characters inside double quotes ending with a null character.
  • ๐Ÿค– AI assistance: GitHub Copilot and similar assistants suggest valid identifiers, flag keyword clashes, and speed up C coding.

C Tokens, Identifiers and Keywords

What is a Character Set in C?

Like every other language, C also has its own character set. A program is a set of instructions that, when executed, generate an output. The data that is processed by a program consists of various characters and symbols. The output generated is also a combination of characters and symbols.

A character set in C is divided into:

  • Letters
  • Numbers
  • Special characters
  • White spaces (blank spaces)

A compiler always ignores the use of characters, but it is widely used for formatting the data. Following is the character set in C programming:

1) Letters

  • Uppercase characters (A-Z)
  • Lowercase characters (a-z)

2) Numbers

  • All the digits from 0 to 9

3) White spaces

  • Blank space
  • New line
  • Carriage return
  • Horizontal tab

4) Special characters

Special characters in C are shown in the given table:

Special Character Description
, (comma) { (opening curly bracket)
. (period) } (closing curly bracket)
; (semi-colon) [ (left bracket)
: (colon) ] (right bracket)
? (question mark) ( (opening left parenthesis)
โ€˜ (apostrophe) ) (closing right parenthesis)
โ€ (double quotation mark) & (ampersand)
! (exclamation mark) ^ (caret)
|(vertical bar) + (addition)
/ (forward slash) โ€“ (subtraction)
\ (backward slash) * (multiplication)
~ (tilde) / (division)
_ (underscore) > (greater than or closing angle bracket)
$ (dollar sign) < (less than or opening angle bracket)
% (percentage sign) # (hash sign)

What is a Token in C?

A token is the smallest unit in a C program. It is each and every word and punctuation that you come across in your C program. The compiler breaks a program into the smallest possible units (tokens) and proceeds to the various stages of the compilation. A C token is divided into six different types, namely Keywords, Operators, Strings, Constants, Special Characters, and Identifiers.

The six types of tokens in C

The next sections look at each of these token types, starting with the two that make up every C statement: keywords and identifiers.

Keywords in C

In C, every word can be either a keyword or an identifier.

Keywords have fixed meanings, and the meaning cannot be changed. They act as the building blocks of a C program. There are a total of 32 keywords in C. Keywords are written in lowercase letters.

The following table represents the keywords in C:

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

Identifiers in C

An identifier is nothing but a name assigned to an element in a program, for example, the name of a variable or a function. Identifiers in C language are the user-defined names consisting of the C standard character set. As the name says, identifiers are used to identify a particular element in a program. Each identifier must have a unique name. The following rules must be followed for identifiers:

  • The first character must always be an alphabet or an underscore.
  • It should be formed using only letters, numbers, or underscore.
  • A keyword cannot be used as an identifier.
  • It should not contain any whitespace character.
  • The name must be meaningful.

Constants in C

A constant is a token whose value does not change during program execution. C constants let you store fixed data, such as numbers or text, and protect it from accidental modification. They fall into a few common categories:

  • Integer constants โ€” whole numbers such as 10, -45, or 0.
  • Floating-point constants โ€” real numbers with a decimal point such as 3.14 or -0.5.
  • Character constants โ€” a single character inside single quotes such as ‘A’ or ‘9’.
  • String constants โ€” a sequence of characters inside double quotes such as “Guru99”.

You can define a constant with the const qualifier or the #define preprocessor directive, for example const int DAYS = 7;. For a deeper look at declaring fixed values, see the guide on the C variable, data types, and constants.

Strings in C

A string in C is a one-dimensional array of characters terminated by a null character (\0). Because C has no dedicated string data type, string literals are stored as character arrays, and the null character marks where the text ends. This lets library functions find the end of the string without a separate length counter.

You can create a string in two common ways:

  • As a character array: char name[] = "Guru99";
  • As a pointer to a literal: char *name = "Guru99";

Both forms store the six visible characters plus the terminating null character. To explore character arrays and text handling further, read the tutorial on strings in C.

Operators in C

An operator is a token that instructs the compiler to perform a specific mathematical, relational, or logical operation on one or more operands. Operators are the action symbols of a C program, and the values they work on are called operands. C groups them into several families:

  • Arithmetic operators โ€” perform calculations, such as +, -, *, /, and %.
  • Relational operators โ€” compare two values, such as ==, !=, >, and <.
  • Logical operators โ€” combine conditions, such as &&, ||, and !.
  • Assignment operators โ€” store a value in a variable, such as = and +=.
  • Bitwise operators โ€” work on individual bits, such as &, |, ^, and ~.

Together with keywords and identifiers, operators let a program express complete instructions that the compiler can translate into machine code.

FAQs

Yes. C is a case-sensitive language, so uppercase and lowercase letters are treated as different. The 32 keywords must be written in lowercase, and identifiers like Total and total refer to two separate elements in the same program.

The C standard sets no hard limit, but a conforming compiler need only treat the first 63 characters of an internal identifier and 31 of an external identifier as significant. Keeping names short and descriptive avoids portability surprises.

No. White spaces, tabs, newlines, and comments are separators that the compiler uses to tell tokens apart, then discards. They are not counted among the six token types, although a blank space can be significant inside a string literal.

During the first phase, called lexical analysis, the compiler scans the source character by character and groups them into the smallest meaningful units. Each token is then classified as a keyword, identifier, constant, string, operator, or special symbol.

A lexeme is the actual sequence of characters in the source code, such as the text int or count. A token is the category the compiler assigns to that lexeme, such as keyword or identifier. Every token comes from a matching lexeme.

A character constant is a single character in single quotes, such as ‘A’, and occupies one byte. A string literal is a sequence of characters in double quotes, such as Guru99, and always ends with a hidden null character, needing one extra byte.

Yes. AI coding assistants suggest valid identifiers, complete keyword-based statements, and flag names that clash with reserved keywords as you type. They can also convert a plain-language comment into correct C declarations, though you should still review the generated code.

GitHub Copilot autocompletes C identifiers, keywords, and whole statements from your comments or variable names. It suggests meaningful names, warns about keyword clashes, and drafts boilerplate, but every suggestion still needs a careful review.

Summarize this post with: