कीवर्ड एक पूर्वनिर्धारित या आरक्षित शब्द है जो C++ लाइब्रेरी में एक निश्चित अर्थ के साथ उपलब्ध है और आंतरिक संचालन करने के लिए उपयोग किया जाता है। C++ भाषा 64 से अधिक कीवर्ड्स का समर्थन करती है।
प्रत्येक कीवर्ड लोअरकेस अक्षरों में होता है जैसे auto, break, case, const, continue, int आदि।
C++ में 32 कीवर्ड्स (C में भी उपलब्ध)
| auto | double | int | struct |
| break | else | long | switch |
| case | enum | register | typedef |
| char | extern | return | union |
| const | float | short | unsigned |
| continue | for | signed | void |
| default | goto | sizeof | volatile |
| do | if | static | while |
C++ में जोड़े गए 30 आरक्षित शब्द
| asm | dynamic_cast | namespace | reinterpret_cast |
| bool | explicit | new | static_cast |
| catch | false | operator | template |
| class | friend | private | this |
| const_cast | inline | public | throw |
| delete | mutable | protected | true |
| try | typeid | typename | using |
| wchar_t |
उदाहरण
इनपुट: str="for" आउटपुट: for is a keyword
एल्गोरिदम
स्ट्रिंग की तुलना प्रत्येक कीवर्ड से करें; यदि समान है तो स्ट्रिंग कीवर्ड है।
C कोड उदाहरण
#include <stdio.h>
#include <string.h>
int main() {
char keyword[32][10] = {
"auto","double","int","struct","break","else","long",
"switch","case","enum","register","typedef","char",
"extern","return","union","const","float","short",
"unsigned","continue","for","signed","void","default",
"goto","sizeof","volatile","do","if","static","while"
};
char str[] = "which";
int flag = 0, i;
for(i = 0; i < 32; i++) {
if(strcmp(str, keyword[i]) == 0) {
flag = 1;
}
}
if(flag == 1)
printf("%s is a keyword", str);
else
printf("%s is not a keyword", str);
return 0;
}
आउटपुट
which is a keyword