Keywords and Identifiers in C Programming

Keywords and Identifiers in C Programming

In this tutorial, you are going to learn about Keywords and Identifiers in C Programming.

Introduction to Tokens

A sentence without words is impossible. Similarly a program in C is impossible to create without tokens. It is the smallest individual unit of a program which is meaningful to the compiler. Token is the building block or the basic component for creating a program in C. It is also known as Lexical Issue.

Tokens in C can be classified as follows: Keywords, Identifiers, Strings, Operators, Constant and Special Characters.

Keywords

  • Predefined set of words which have special meaning within the compiler.
  • Each keyword has its own functionality and they cannot be used as variable names.
  • If the keywords are used as the variable names, it means that we are assigning a different meaning to the keyword which is not permitted.
  • C language supports 32 keywords which are stated below:

Example: double a, b, c; Here double is a data type and is a keyword.

Supported Keywords in C

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

Identifiers

  • Used for Naming variables, functions and arrays.
  • These are user defined words composed of uppercase, lowercase letters, underscore, or digits but the starting letter should either be an underscore or an alphabet.
  • Identifiers cannot be used as keywords.

Naming Rules of Identifiers

  • The first character of an identifier should either be an alphabet or an underscore sign (_). The next characters can either be a digit, a character or underscore.
  • There should not be any space between variable names.
  • It should not begin with any numerical digit.
  • Identifiers are case-sensitive as it distinguishes between uppercase and lower case letters.
  • Commas or blank spaces cannot be specified within an identifier.
  • An identifier cannot be a keyword.

Example:

void main()
{
int a=5;
}

Here main and a are identifiers.


This post is written by Divyanshu Shekhar (BTech CS, Chandigarh Engineering College). If you like TheCode11, then do follow us on Facebook, Twitter and Instagram.

Previous Post Next Post

Contact Form