Keywords in C++
Below is the list of keywords in C++:
asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while
Example:
#include <iostream>
using namespace std;
int main()
{
// int, double, char, bool keywords
int age = 30;
double pi = 3.14159;
char initial = 'B';
bool isTrue = true;
// if, else keywords
if (age > 25) {
cout << "You are eligible." << endl;
}
else {
cout << "Not yet eligible." << endl;
}
// for keyword
for (int i = 0; i < 5; i++) {
cout << "Iteration " << i << endl;
}
// while keyword
int count = 0;
while (count < 3) {
cout << "Count: " << count << endl;
count++;
}
// Switch, case keywords
switch (initial) {
case 'A':
cout << "Initial is A" << endl;
break;
case 'B':
cout << "Initial is B" << endl;
break;
default:
cout << "Initial is something else" << endl;
}
return 0;
}
Output
You are eligible. Iteration 0 Iteration 1 Iteration 2 Iteration 3 Iteration 4 Count: 0 Count: 1 Count: 2 Initial is B
What is Keyword in Programming?
Keywords are predefined or reserved words that have special meaning to the compiler. In this article, we will discuss about keywords in programming, its importance, and usage in different languages.
Contact Us