Identifiers in C Programming

🎓 Lecture Article: Identifiers in C Programming

What Are Identifiers?
In C programming, identifiers are the names you use to identify variables, functions, arrays, structures, and other user-defined elements.

Example: When you write int age;, age is an identifier.


📌 Purpose of Identifiers

Identifiers let the compiler and programmer refer to data and functions throughout the program.

  • Declare variables: int marks;
  • Define functions: void printReport();
  • Use for arrays, structures, constants, etc.

🧠 Rules for Naming Identifiers in C

  • Must begin with a letter (A–Z or a–z) or underscore (_)
  • Can contain letters, digits (0–9), and underscores after the first character
  • No special characters allowed (e.g., @, #, $, %, space)
  • Cannot be the same as a keyword (e.g., int, return)
  • C is case-sensitive: Total and total are different

🧪 Valid Identifier Examples

int age;
float temperature;
char name[50];
int _count;
double salary2025;

❌ Invalid Identifier Examples

int 2ndNumber;     // ❌ Cannot start with a digit
float total$;      // ❌ Invalid character
char void;         // ❌ 'void' is a keyword
int first name;    // ❌ Cannot have space

🔍 Identifier vs Keyword

Feature Identifier Keyword
Purpose User-defined names Predefined by the language
Modifiable? Yes No
Examples score, totalSum, getData int, return, while

📘 Example Program Using Identifiers

#include <stdio.h>

int main() {
    int studentAge = 20;
    float finalScore = 88.5;

    printf("Student Age: %d\n", studentAge);
    printf("Final Score: %.2f\n", finalScore);

    return 0;
}

🟢 Here, studentAge and finalScore are identifiers.
🔵 int, float, return are keywords.


💡 Tips for Good Identifier Naming

  • ✅ Use descriptive names: totalMarks, employeeSalary
  • ❌ Avoid vague names: x, data1, temp
  • Use camelCase or underscores for readability

📝 Summary

  • Identifiers are used to name user-defined elements like variables and functions.
  • They must follow C's naming rules.
  • They are case-sensitive and cannot be the same as keywords.
  • Descriptive names improve code readability and maintenance.

🎯 Homework / Practice

  1. Write a program that declares at least 5 variables using valid identifiers.
  2. Find and fix 3 invalid identifier examples.
  3. Explain in your own words the difference between identifiers and keywords.

একটি মন্তব্য পোস্ট করুন