← Back to C Course | Chapter 1: Introduction & Basics | Lesson 8 of 21

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

c
#include <stdio.h>
int main() {
	int x = 5;
	if (x) {
		return 0;
	}
	return 1;
}

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

c
#include <stdio.h>
int main() {
	int totalPrice = 50;
	printf("%d", totalPrice);
	return 0;
}

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

c
#include <stdio.h>
int main() {
	int _count = 1;
	int total2 = 2;
	printf("%d %d", _count, total2);
	return 0;
}

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

c
#include <stdio.h>
int main() {
	int count = 1;
	int Count = 2;
	printf("%d %d", count, Count);
	return 0;
}

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

c
#include <stdio.h>
int main() {
	int studentAge = 20;
	for (int i = 0; i < 3; i++) {
		printf("%d ", studentAge);
	}
	return 0;
}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.