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

C Keywords & Identifiers

Keywords are words C has reserved for its own jobs, like reserved parking spots. Identifiers are the names you give your own things, following the naming rules.
Syntax
c
type identifier = value;   // identifier: letters, digits, _ (no leading digit)
int count = 10;            // int is a reserved keyword

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 standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare x and set it to 5
	int x = 5;
	// Check whether x
	if (x) {
		// Send 0 back to the caller
		return 0;
	}
	// Send 1 back to the caller
	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 standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare totalPrice and set it to 50
	int totalPrice = 50;
	// Print formatted text to the screen
	printf("%d", totalPrice);
	// Return 0 to signal that the program finished successfully
	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 standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare _count and set it to 1
	int _count = 1;
	// Declare total2 and set it to 2
	int total2 = 2;
	// Print formatted text to the screen
	printf("%d %d", _count, total2);
	// Return 0 to signal that the program finished successfully
	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 standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare count and set it to 1
	int count = 1;
	// Declare Count and set it to 2
	int Count = 2;
	// Print formatted text to the screen
	printf("%d %d", count, Count);
	// Return 0 to signal that the program finished successfully
	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 standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare studentAge and set it to 20
	int studentAge = 20;
	// Loop: repeat while the condition holds
	for (int i = 0; i < 3; i++) {
		// Print formatted text to the screen
		printf("%d ", studentAge);
	}
	// Return 0 to signal that the program finished successfully
	return 0;
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Using a keyword such as int for = 5; as a variable name, which is a compile error.
  2. Starting an identifier with a digit like 1stValue, which is not allowed.
  3. Mixing up total and Total, since identifiers are case-sensitive and are different names.

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.