C++ Keywords

🗝️ 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 variable
  • float – Declares a floating-point variable
  • double – Declares a double-precision variable
  • char – Declares a character variable
  • bool – Declares a boolean variable (true/false)
  • void – Used for functions that return nothing
  • if, else – Used for decision-making
  • for, while, do – Loops
  • break, continue – Control loop flow
  • return – Ends a function and optionally returns a value
  • const – Defines constant values
  • class, 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;
}

Try It Now

🚫 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.