C Variable Names (Identifiers)

C Tutorial

 C Variable Names (Identifiers) – Complete Guide

In C language, variable names are also called identifiers.
They are used to identify variables, functions, arrays, and other user-defined items in a program.

Choosing correct and meaningful identifiers is important for readability, correctness, and interviews.


1️⃣ What is an Identifier in C?

An identifier is the name given to a variable, function, array, or any other user-defined element.

int age;
float totalMarks;
char grade;

Here:

  • age, totalMarks, grade → identifiers


2️⃣ Rules for Naming Identifiers ⭐ (Very Important)

C identifiers must follow these rules:

✅ Allowed

  1. Can contain letters (a–z, A–Z)

  2. Can contain digits (0–9)

  3. Can contain underscore _

  4. Must start with a letter or underscore

❌ Not Allowed

  1. Cannot start with a digit

  2. Cannot contain special symbols (@, #, $, %, etc.)

  3. Cannot be a C keyword

  4. Cannot contain spaces


3️⃣ Valid Identifier Examples ✅

✔ All follow C naming rules


4️⃣ Invalid Identifier Examples ❌

int 1num; // ❌ starts with digit
float total-m; // ❌ special character '-'
char my name; // ❌ space not allowed
int int; // ❌ keyword

5️⃣ Case Sensitivity in C ⭐

C is case-sensitive.

int age;
int Age;

age and Age are different identifiers


6️⃣ Keywords Cannot Be Identifiers ❌

C keywords are reserved words.

Examples:

int for; // ❌
float while; // ❌
char return; // ❌

Some common C keywords:

int, float, char, if, else, for, while, return, void

7️⃣ Length of Identifiers ⚠️

  • C allows long identifiers

  • At least 31 characters are significant (compiler dependent)

int this_is_a_very_long_variable_name;

✔ Valid, but keep names readable


8️⃣ Naming Conventions (Best Practices) ⭐

Although not mandatory, follow these good practices:

 Use-meaningful names

int totalMarks; // ✅
int x; // ❌ unclear

 Use-lowercase for variables

int studentCount;

 Use-uppercase for constants

#define MAX_SIZE 100

 Use-underscore for multi-word names

float total_salary;

9️⃣ Identifiers for Different Elements

Variable

int marks;

Function

int calculateSum();

Array

int scores[5];

Structure

struct Student {
int id;
};

🔟 Identifier vs Variable Name ⭐

Term Meaning
Identifier Name of any user-defined element
Variable Name Identifier that stores a value

📌 Every variable name is an identifier, but not every identifier is a variable


1️⃣1️⃣ Common Mistakes ❌

❌ Using keywords as names
❌ Starting with digits
❌ Using special symbols
❌ Writing unreadable names
❌ Confusing case sensitivity


📌 Interview Questions (Must Prepare)

  1. What is an identifier in C?

  2. Rules for naming identifiers

  3. Can identifier start with _?

  4. Is C case-sensitive?

  5. Difference between keyword and identifier

  6. Maximum length of identifier in C


✅ Summary

✔ Identifiers are names given to program elements
✔ Must start with letter or _
✔ Cannot use keywords or special symbols
✔ C is case-sensitive
✔ Good naming improves readability & maintenance
✔ Very important for basics, exams & interviews

You may also like...