C++ Keywords šŸŽÆ

beginner
14 min

C++ Keywords šŸŽÆ

Welcome to our comprehensive guide on C++ Keywords! This tutorial is designed to help both beginners and intermediate learners understand the fundamental building blocks of the C++ programming language. Let's dive in!

What are Keywords in C++? šŸ“

In programming, keywords are reserved words that have special meanings and are used to define various programming constructs. In C++, these keywords help us create variables, control flow, and define functions, among other things.

C++ Keywords List šŸ“

Here's a list of C++ keywords that you'll encounter frequently:

  1. auto
  2. break
  3. case
  4. catch
  5. char
  6. class
  7. const
  8. constexpr
  9. continue
  10. default
  11. delete
  12. do
  13. double
  14. dynamic_cast
  15. else
  16. enum
  17. explicit
  18. export
  19. extensible
  20. extern
  21. false
  22. float
  23. for
  24. friend
  25. goto
  26. if
  27. inline
  28. int
  29. long
  30. namespace
  31. new
  32. noexcept
  33. not
  34. null
  35. operator
  36. private
  37. protected
  38. public
  39. register
  40. reinterpret_cast
  41. return
  42. short
  43. signed
  44. sizeof
  45. static
  46. static_cast
  47. static_assert
  48. struct
  49. switch
  50. template
  51. this
  52. thread_local
  53. throw
  54. true
  55. try
  56. typedef
  57. typeid
  58. typename
  59. union
  60. unordered_map
  61. unordered_set
  62. unsigned
  63. using
  64. virtual
  65. void
  66. volatile
  67. wchar_t
  68. while
  69. xor

Understanding Keywords with Examples šŸ’”

Let's take a look at some examples to understand how these keywords are used in practice.

Example 1: Variables with int and char šŸ’”

cpp
#include <iostream> int main() { int age = 25; // An integer variable char name = 'A'; // A character variable std::cout << "My age is: " << age << std::endl; std::cout << "My name is: " << name << std::endl; return 0; }

In the example above, int and char are C++ keywords used to declare integer and character variables, respectively.

Example 2: Control Flow with if, else, and switch šŸ’”

cpp
#include <iostream> int main() { int age = 25; if (age > 18) { std::cout << "You are an adult."; } else { std::cout << "You are a minor."; } // Using switch int day = 3; switch (day) { case 1: std::cout << "Today is Monday."; break; case 2: std::cout << "Today is Tuesday."; break; case 3: std::cout << "Today is Wednesday."; break; // Add more cases as needed default: std::cout << "Invalid day."; } return 0; }

In the second example, we use if, else, and switch to control the flow of our program.

Quiz šŸ’”

Quick Quiz
Question 1 of 1

What is the purpose of the `int` keyword in C++?

Happy coding! šŸŽ‰