- C Programming Tutorial
- C - Home
- Basics of C
- C - Introduction
- C - Features
- C - Basics
- C - History
- C - Structure of C Program
- C - Program Structure
- C - Hello World
- C - Compilation Process
- C - Comments
- C - Tokens
- C - Keywords
- C - Identifiers
- C - User Input
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Integer Promotions
- C - Type Conversion
- C - Type Casting
- C - Booleans
- Constants and Literals in C
- C - Constants
- C - Literals
- C - Escape sequences
- C - Format Specifiers
- Operators in C
- C - Operators
- C - Arithmetic Operators
- C - Relational Operators
- C - Logical Operators
- C - Bitwise Operators
- C - Assignment Operators
- C - Unary Operators
- C - Increment and Decrement Operators
- C - Ternary Operator
- C - sizeof Operator
- C - Operator Precedence
- C - Misc Operators
- Decision Making in C
- C - Decision Making
- C - if statement
- C - if...else statement
- C - nested if statements
- C - switch statement
- C - nested switch statements
- Loops in C
- C - Loops
- C - While loop
- C - For loop
- C - Do...while loop
- C - Nested loop
- C - Infinite loop
- C - Break Statement
- C - Continue Statement
- C - goto Statement
- Functions in C
- C - Functions
- C - Main Function
- C - Function call by Value
- C - Function call by reference
- C - Nested Functions
- C - Variadic Functions
- C - User-Defined Functions
- C - Callback Function
- C - Return Statement
- C - Recursion
- Scope Rules in C
- C - Scope Rules
- C - Static Variables
- C - Global Variables
- Arrays in C
- C - Arrays
- C - Properties of Array
- C - Multi-Dimensional Arrays
- C - Passing Arrays to Function
- C - Return Array from Function
- C - Variable Length Arrays
- Pointers in C
- C - Pointers
- C - Pointers and Arrays
- C - Applications of Pointers
- C - Pointer Arithmetics
- C - Array of Pointers
- C - Pointer to Pointer
- C - Passing Pointers to Functions
- C - Return Pointer from Functions
- C - Function Pointers
- C - Pointer to an Array
- C - Pointers to Structures
- C - Chain of Pointers
- C - Pointer vs Array
- C - Character Pointers and Functions
- C - NULL Pointer
- C - void Pointer
- C - Dangling Pointers
- C - Dereference Pointer
- C - Near, Far and Huge Pointers
- C - Initialization of Pointer Arrays
- C - Pointers vs. Multi-dimensional Arrays
- Strings in C
- C - Strings
- C - Array of Strings
- C - Special Characters
- C Structures and Unions
- C - Structures
- C - Structures and Functions
- C - Arrays of Structures
- C - Self-Referential Structures
- C - Lookup Tables
- C - Dot (.) Operator
- C - Enumeration (or enum)
- C - Structure Padding and Packing
- C - Nested Structures
- C - Anonymous Structure and Union
- C - Unions
- C - Bit Fields
- C - Typedef
- File Handling in C
- C - Input & Output
- C - File I/O (File Handling)
- C Preprocessors
- C - Preprocessors
- C - Pragmas
- C - Preprocessor Operators
- C - Macros
- C - Header Files
- Memory Management in C
- C - Memory Management
- C - Memory Address
- C - Storage Classes
- Miscellaneous Topics
- C - Error Handling
- C - Variable Arguments
- C - Command Execution
- C - Math Functions
- C - String Functions
- C - Static Keyword
- C - Random Number Generation
- C - Command Line Arguments
C Programming - C Identifiers
![]() Share with a Friend |
C Programming - C Identifiers
C Identifiers
In the C programming language, an identifier is the name used to identify variables, functions, arrays, or any user-defined element. Identifiers are fundamental for writing meaningful and readable code.
Characteristics of C Identifiers
- Uniqueness:
- Each identifier must be unique within its scope.
- Case Sensitivity:
- Identifiers are case-sensitive (age and Age are different).
- Defined Rules:
- Must begin with a letter (A-Z or a-z) or an underscore (_).
- Can be followed by letters, digits (0-9), or underscores.
- Cannot use special symbols like @, $, %, etc.
- Cannot be a keyword or reserved word.
Rules for Naming Identifiers
- Start with a Letter or Underscore:
- Valid: name, _temp
- Invalid: 1stName, -value
- No Spaces:
- Valid: first_name
- Invalid: first name
- No Special Characters:
- Valid: value1
- Invalid: value#1
- Avoid Keywords:
- Valid: data
- Invalid: int
Examples of Valid and Invalid Identifiers
| Valid Identifiers | Invalid Identifiers |
|---|---|
total |
123total |
_result |
total@result |
num123 |
int |
sum_of_numbers |
sum of numbers |
Examples in Code
Valid Identifiers
#include <stdio.h>
int main() {
int age = 25; // 'age' is a valid identifier
float _salary = 50000.50; // '_salary' is a valid identifier
char grade = 'A'; // 'grade' is a valid identifier
printf("Age: %d\n", age);
printf("Salary: %.2f\n", _salary);
printf("Grade: %c\n", grade);
return 0;
}
Invalid Identifiers
#include <stdio.h>
int main() {
int 1number = 10; // Error: Identifier cannot start with a digit
float total$ = 100.5; // Error: Special characters are not allowed
char return = 'B'; // Error: 'return' is a keyword
return 0;
}
Best Practices for Naming Identifiers
- Use Descriptive Names:
- Instead of x or y, use student_age or total_score for clarity.
- Follow Naming Conventions:
- Use camelCase (studentAge) or snake_case (student_age) consistently.
- Avoid Ambiguity:
- Choose names that clearly indicate their purpose.
- Limit Length:
- Avoid extremely long names, but ensure they are descriptive.
Key Points
- Identifiers are essential for writing readable and maintainable code.
- Always follow the naming rules to avoid compilation errors.
- Use meaningful names to enhance code clarity and ease debugging.
