Chapter 06 of 37

Keywords and Identifiers

When writing a C program, you'll see names like age, marks, and main, along with special words like int, return, and if.

These are not all the same. Some are keywords, while others are identifiers.

Let's understand the difference.

What are Keywords?

Keywords are reserved words in C that have a predefined meaning to the compiler.

For example:

int age = 20;
return 0;

Here, int and return are keywords.

You cannot use keywords as variable or function names.

For example:

int int = 10;   // ❌ Invalid

because int is already a keyword in C.

Some commonly used C keywords are:

Keyword

Purpose

int

Defines an integer

float

Defines a floating-point value

char

Defines a character

if

Checks a condition

else

Provides an alternative

for

Creates a loop

while

Creates a loop

return

Returns a value

void

Represents no value

C has a fixed set of keywords defined by the language standard, and we'll encounter them naturally as we learn different topics.


What are Identifiers?

Identifiers are names given by the programmer to program elements such as variables, functions, arrays, and structures.

For example:

int age = 20;

Here:

  • int → keyword

  • age → identifier

  • 20 → value

We choose the name age ourselves, so it is an identifier.

Other examples:

int marks;
float price;

void display()
{
    // ...
}

Here, marks, price, and display are identifiers.


Rules for Naming Identifiers

There are some rules you need to follow when creating identifiers.

Valid identifiers

age
studentName
marks1
total_marks

Invalid identifiers

1age          // ❌ Starts with a digit
student name  // ❌ Contains a space
float         // ❌ Keyword

The basic rules are:

  • Can contain letters, digits, and underscores (_)

  • Cannot start with a digit

  • Cannot contain spaces

  • Cannot be a C keyword

  • C is case-sensitive

So:

age
Age
AGE

are three different identifiers.


Keywords vs Identifiers

Keywords

Identifiers

Reserved by C

Created by the programmer

Have predefined meanings

Used to name program elements

Cannot be used as variable names

Can be used as variable/function names

Example: int, if, return

Example: age, marks, total

Simple Example

Look at this program:

#include <stdio.h>

int main()
{
    int marks = 90;

    printf("%d", marks);

    return 0;
}

Here:

  • int → keyword

  • main → identifier

  • marks → identifier

  • printf → function name

  • return → keyword

In Simple Words

Keywords are predefined words reserved by C, while identifiers are names created by the programmer.

A simple way to remember it:

C decides the keywords; you decide the identifiers.