🗝️ C++ Keywords – Reserved Words You Must Know
Keywords are special reserved words in C++ that have predefined meanings. You can’t use them as variable names — they’re off-limits! 🛑
Think of them like VIPs in the C++ language — they’re busy doing official work and can’t be renamed. 😄
📚 Common C++ Keywords
int– Declares an integer variablefloat– Declares a floating-point variabledouble– Declares a double-precision variablechar– Declares a character variablebool– Declares a boolean variable (true/false)void– Used for functions that return nothingif,else– Used for decision-makingfor,while,do– Loopsbreak,continue– Control loop flowreturn– Ends a function and optionally returns a valueconst– Defines constant valuesclass,public,private– Used in object-oriented programming
🎯 Example: Using Some C++ Keywords
Here’s a simple program using multiple keywords to show how they work in action:
#include <iostream>
using namespace std;
int main() {
const int limit = 3;
int i;
for (i = 0; i < limit; i++) {
cout << "Keyword loop " << i << endl;
}
return 0;
}
🚫 Important:
- You cannot use a keyword as a variable name. For example,
int if = 5;❌ is illegal. - There are over 80 keywords in C++, but you’ll mostly use a handful when starting out.