C Keywords & Identifiers
Keywords
Keywords are words the C language reserves for its own syntax -- int, return, if, while, and about 30 others -- and the compiler will reject any attempt to use one of them as a variable or function name.
Example: Keywords
#include <stdio.h>
int main() {
int x = 5;
if (x) {
return 0;
}
return 1;
}
Login to try C/C++/Java/PHP code in the editor
Identifiers
An identifier is any name you choose for a variable, function, or array in your own code. Picking clear identifiers (like totalPrice instead of x) makes your program far easier to read months later or for someone else reviewing it.
Example: Identifiers
#include <stdio.h>
int main() {
int totalPrice = 50;
printf("%d", totalPrice);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Naming Rules
C requires every identifier to start with a letter or underscore, and to contain only letters, digits, and underscores after that -- names like 2total or total-price will fail to compile because they break these rules.
Example: Naming Rules
#include <stdio.h>
int main() {
int _count = 1;
int total2 = 2;
printf("%d %d", _count, total2);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Case Sensitivity in Names
Because C treats case as significant, count and Count are two distinct identifiers that could coexist in the same scope -- a frequent source of subtle bugs when a typo accidentally introduces a second, unintended variable.
Example: Case Sensitivity in Names
#include <stdio.h>
int main() {
int count = 1;
int Count = 2;
printf("%d %d", count, Count);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Best Practices for Names
Favor descriptive multi-word names like studentAge over cryptic single letters, except for very short-lived loop counters like i, where the convention is well understood and brevity doesn't hurt readability.
Example: Best Practices for Names
#include <stdio.h>
int main() {
int studentAge = 20;
for (int i = 0; i < 3; i++) {
printf("%d ", studentAge);
}
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Chapter Quiz — Complete all 21 topics to unlock
0/21 topics done
Complete these topics first:
- C Introduction
- C History & Features
- C Environment Setup
- C First Program
- C Syntax & Structure
- C Statements
- C Comments
- C Keywords & Identifiers
- C Data Types
- C Character Data Type
- C Numeric Data Types
- C Decimal (Floating-Point) Numbers
- C sizeof Operator
- C Extended Data Types
- C Type Conversion
- C Booleans
- C Variables
- C Changing Variable Values
- C Multiple Variables
- C Constants
- C Fixed-Width Integers