In this tutorial, we are going to learn about keywords in C++. This is a very important concept to be understood at the beginning itself because, in many programs ahead, we are going to use different keywords for different purposes. We will see different keywords in C++, so that we can later use them, in our C++ programs.
CPP Keywords
What are keywords in CPP?
Keywords are some words whose meaning is already known to the compiler. In other words, we can say that keywords have some predefined meaning, and they have a special purpose, and can be used just where they are supposed to be used, and not anywhere else.
For example, let’s say that we have a toolbox, with some tools used for construction. In that toolbox, we have various tools, which are used for some special purpose, and not for anything else. Just like that, we have different keywords in C++, which can be used only where they are supposed to be used.
Note that if you know some basic C programming, then all the keywords from the C language are included here, and additionally there are some more keywords in C++. The number of keywords can depend on the version of C++, but as in C++ 20, there are a total of 93 keywords. Here is a brief list of some keywords in C++
return | float | int | void |
break | continue | if | else |
switch | case | for | while |
struct | union | long | signed |
do | default | sizeof | double |
char | register | void | const |
unsigned | short | goto | volatile |
static | extern | typedef | enum |
All the keywords are also present in the C language. Additional keywords are as given below –
try | catch | throw | class |
bool | private | protected | public |
this | wchar_t | new | true |
false | using | namespace | not |
friend | virtual | typename | typeid |
operator | xor | bitor | bitand |
auto | inline | import | or |
and | export | delete |
There are many more keywords in C++, while many of the above-stated will be used more often. Feel free to explore the keywords. You will get used to it since we will be using many of them from time to time.
Summary
In this tutorial, we learned about keywords in C++. Certainly, keywords are some reserved words, whose meaning is already known to the compiler. They can be used only in the places where they are supposed to be used.
As you move ahead doing several programs, you would then use a lot of different keywords, more of the above mentioned more frequently, and then you would get familiar with these keywords.
FAQs related to Keywords in CPP
Q: What are keywords in C++?
Ans: Keywords can be considered as some special words, which have some predefined meaning, and they can be used only where they are supposed to be used, and not anywhere else. There are many keywords in C++, like – break, if, else, int, for, while, do, etc.
Q: How many keywords are there in C++?
Ans: As of C++ 20, there is a total of 93 keywords in C++.
Q: Are all the keywords from C there in C++?
Ans: Yes, all the keywords from C are there in C++, and there are some additional keywords in C++.