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

C Keywords और Identifiers

Keywords वे words हैं जो C ने अपने काम के लिए reserve किए हैं, जैसे reserved parking spots। Identifiers वे नाम हैं जो आप naming rules follow करते हुए अपनी चीज़ों को देते हैं।
Syntax
c
type identifier = value;   // identifier: letters, digits, _ (no leading digit)
int count = 10;            // int is a reserved keyword

Keywords

Keywords वे words हैं जिन्हें C language अपने syntax के लिए reserve करती है -- int, return, if, while, और लगभग 30 और -- और compiler इनमें से किसी को भी variable या function नाम की तरह इस्तेमाल करने की कोशिश को reject कर देगा।

उदाहरण: 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

एक identifier आपके अपने code में किसी variable, function, या array के लिए चुना गया कोई भी नाम है। clear identifiers चुनना (जैसे x की बजाय totalPrice) आपके program को महीनों बाद या इसे review करने वाले किसी और के लिए पढ़ना कहीं आसान बना देता है।

उदाहरण: 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 को हर identifier का एक letter या underscore से शुरू होना ज़रूरी है, और उसके बाद सिर्फ letters, digits, और underscores होने चाहिए -- 2total या total-price जैसे नाम compile नहीं होंगे क्योंकि वे इन rules को तोड़ते हैं।

उदाहरण: 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

क्योंकि C case को significant मानता है, count और Count दो distinct identifiers हैं जो same scope में साथ exist कर सकते हैं -- subtle bugs का एक common source जब एक typo गलती से एक दूसरा, unintended variable introduce कर देता है।

उदाहरण: 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

cryptic single letters पर studentAge जैसे descriptive multi-word names पसंद करें, i जैसे बहुत short-lived loop counters को छोड़कर, जहाँ convention अच्छे से समझी जाती है और brevity readability को नुकसान नहीं पहुंचाती।

उदाहरण: 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. #}
आम गलतियां
  1. int for = 5; जैसे keyword को variable नाम की तरह इस्तेमाल करना, जो एक compile error है।
  2. 1stValue जैसे किसी digit से identifier शुरू करना, जो allowed नहीं है।
  3. total और Total को मिला देना, क्योंकि identifiers case-sensitive हैं और अलग नाम हैं।

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.