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.


 What is an Identifier in C?

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

Here:

  • age, totalMarks, grade → identifiers


 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


 Valid Identifier Examples

  •  All follow C naming rules

 Invalid Identifier Examples


 Case Sensitivity in C

C is case-sensitive.

  • age and Age are different identifiers

 Keywords Cannot Be Identifiers

C keywords are reserved words.

Examples:

Some common C keywords:

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

 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

 Naming Conventions (Best Practices)

Although not mandatory, follow these good practices:

 Use-meaningful names

 Use-lowercase for variables

 Use-uppercase for constants

 Use-underscore for multi-word names


 Identifiers for Different Elements

Variable

Function

Array

Structure


 Identifier vs Variable Name

TermMeaning
IdentifierName of any user-defined element
Variable NameIdentifier that stores a value
  •  Every variable name is an identifier, but not every identifier is a variable

 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...