C++ Keywords और Identifiers
In this page:
type identifier = value; // identifier: letters, digits, _ (no leading digit)
int age = 25; // int is a reserved keyword
Keywords
Keywords वे words हैं जिन्हें खुद C++ language specific purposes के लिए reserve करती है, जैसे int, return, और class, और compiler इन्हें एक fixed meaning देता है जिसे repurpose नहीं किया जा सकता।
एक variable को int या class नाम देने की कोशिश compile नहीं होगी, क्योंकि compiler उन words को सिर्फ उनके reserved role में appear होने की उम्मीद करता है।
उदाहरण: Keywords
#include <iostream>
int main() {
// 'int', 'return' are keywords -- reserved, fixed meaning
int age = 25;
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Identifiers
Identifiers वे नाम हैं जो आप variables, functions, और classes के लिए चुनते हैं, और clear नाम चुनना code को पढ़ना आसान बनाने के सबसे सस्ते तरीकों में से एक है।
totalPrice नाम का एक variable इसका purpose instantly communicate करता है, जबकि x जैसा एक नाम code पढ़ने वाले किसी को भी इसे समझने के लिए logic में वापस track करने पर मजबूर करता है।
उदाहरण: Identifiers
#include <iostream>
int main() {
int totalPrice = 100; // clear identifier vs an unclear name like x
std::cout << totalPrice << std::endl;
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Naming Rules
C++ को identifiers का एक letter या underscore (कभी digit नहीं) से शुरू होना ज़रूरी है, और उसके बाद सिर्फ letters, digits, और underscores होने चाहिए — कोई spaces, hyphens, या $ या # जैसे symbols नहीं।
ये rules इसलिए exist करते हैं क्योंकि compiler को एक unambiguous तरीका चाहिए यह बताने का कि एक identifier कहाँ खत्म होता है और अगला token कहाँ शुरू होता है।
उदाहरण: Naming Rules
#include <iostream>
int main() {
int _count = 0; // starts with underscore: valid
int count2 = 1; // letters/digits only: valid
std::cout << _count << " " << count2 << std::endl;
return 0;
}
Login to try C/C++/Java/PHP code in the editor
नामों में Case Sensitivity
क्योंकि C++ case-sensitive है, count और Count compiler के लिहाज़ से दो पूरी तरह distinct identifiers हैं, भले ही वे एक human को लगभग identical दिखें।
यह 'undefined reference' errors का एक common source है जब एक variable एक casing से declared होता है और गलती से दूसरी से इस्तेमाल होता है।
उदाहरण: Case Sensitivity in Names
#include <iostream>
int main() {
int count = 1;
int Count = 2; // a distinct identifier from 'count'
std::cout << count << " " << Count << std::endl;
return 0;
}
Login to try C/C++/Java/PHP code in the editor
नामों के लिए Best Practices
Abbreviations या single letters के मुकाबले descriptive, specific names पसंद करें, i जैसे बहुत short-lived loop counters को छोड़कर जहाँ convention अच्छे से समझी जाती है।
एक codebase में consistent naming conventions — जैसे variables के लिए हमेशा camelCase इस्तेमाल करना — unfamiliar code को जल्दी skim और समझना कहीं आसान बनाते हैं।
उदाहरण: Best Practices for Names
#include <iostream>
int main() {
for (int i = 0; i < 3; i++) { // short name OK for a loop counter
int orderTotal = i * 10; // descriptive name elsewhere
std::cout << orderTotal << std::endl;
}
return 0;
}
Login to try C/C++/Java/PHP code in the editor
int class = 5;याnewजैसे keyword इस्तेमाल करना, जो reserved है और एक compile error cause करता है।2ndPlaceजैसे किसी digit से identifier शुरू करना, जो एक legal name नहीं है।countऔरCountको मिला देना, क्योंकि identifiers case-sensitive हैं और ये दो अलग नाम हैं।
Chapter Quiz — Complete all 15 topics to unlock
0/15 topics done
Complete these topics first: