✍️ C++ Basic Syntax & Language Elements
Estimated reading: 3 minutes 31 views

πŸ”‘ C++ Keywords – Reserved Words Every Programmer Must Know


🧲 Introduction – What Are Keywords in C++?

Keywords in C++ are reserved words that have special meaning to the compiler. These words are part of the C++ language syntax and cannot be used as names for variables, functions, classes, or identifiers. They play a fundamental role in defining the structure and behavior of C++ programs.

🎯 In this guide, you’ll learn:

  • What keywords are and why they matter
  • The full list of C++ keywords (updated for C++23)
  • How keywords are used in actual programs
  • Common beginner mistakes to avoid

πŸ“˜ What Is a Keyword in C++?

A keyword is a built-in command or symbol that tells the C++ compiler to perform a specific task or recognize a syntactic construct.

int main() {
    return 0;
}

In the code above:

  • int and return are keywords
  • main is an identifier, not a keyword

🧾 List of C++ Keywords (Including C++11 – C++23)

πŸ”Ή CategoryπŸ”‘ Keywords
Data Typesint, char, float, double, bool, void, wchar_t
Control Statementsif, else, switch, case, default, break, continue, goto, do, while, for
Modifiersconst, static, mutable, volatile, register, extern, inline
Classes/OOPclass, struct, union, enum, public, private, protected, virtual, friend, this, new, delete
Functionsreturn, try, catch, throw, noexcept, explicit, operator, override, final
Templatestemplate, typename, using, namespace
Boolean & Nulltrue, false, nullptr
Type Operatorssizeof, typeid, decltype, alignof
Coroutines (C++20)co_await, co_yield, co_return
Modern C++constexpr, consteval, constinit, concept, requires, static_assert, import, module

βœ… Total: Over 95 keywords, updated with each standard release.


πŸ§ͺ Example – Keywords in Use

#include <iostream>

int main() {
    const int maxMarks = 100;   // const is a keyword
    int score = 85;

    if (score < maxMarks) {
        std::cout << "You passed!" << std::endl;
    }
    return 0;
}

πŸ” In this example:

  • int, const, if, and return are keywords.
  • main, maxMarks, and score are identifiers.

⚠️ Common Mistakes with Keywords

❌ Mistakeβœ… Correction
Using a keyword as a variableint int = 5; β†’ ❌ Illegal
Typing keyword in uppercaseReturn β‰  return (C++ is case-sensitive)
Assuming main is a keywordmain is not a keywordβ€”it’s a special name
Trying to redefine keywordsCannot define int or class as identifiers

πŸ“Œ Summary – Recap & Next Steps

πŸ” Key Takeaways:

  • Keywords are reserved words with predefined purposes in C++
  • You cannot use them as names for variables or functions
  • Learn and recognize all standard keywords, especially as C++ evolves
  • Understanding keyword usage is essential for valid program syntax

βš™οΈ Real-World Relevance:
A deep understanding of keywords helps prevent syntax errors, improves code readability, and ensures that your programs follow modern C++ standards.


❓ FAQs – C++ Keywords

❓ Are C++ keywords case-sensitive?
βœ… Yes. int is valid, but Int is treated as an identifier.

❓ Can I use keywords as variable names?
❌ No. Keywords are reserved and cannot be redefined or reused.

❓ Is main a keyword?
❌ No. It’s a special function name, not a keyword.

❓ What are new keywords in C++20 and C++23?
βœ… Examples include concept, requires, consteval, co_await, and module.

❓ How many keywords are there in modern C++?
βœ… Over 95 keywords, with additions in every major C++ standard.


Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

C++ Keywords

Or Copy Link

CONTENTS
Scroll to Top