Basic Terminologies in C++ – C++ – Lecture 3
In the previous post, we learned how a C++ program actually works! In this article, let us get a quick overview of the basic terminologies in C++ programming. The compiler processes the code, it treats each word(group of characters separated by white space) as a token. Token is the smallest individual unit of our program understandable by the compiler(think of it as an atom, the building block of our code). Now, these tokens are broadly divided into 6 categories.
Let us use the below code as a reference to understand the basic terminologies in C++.
#define NUM 5 #include <iostream> using namespace std; int main() { std::cout << "Hello World"; int n; cin >> n; cout << n + 2; return 0; }
1. Keyword
Keywords are pre-defined words(reserved words i.e., not user-defined) that already have a meaning assigned to them for a particular purpose. They are always denoted by lowercase. There are a total of 95 keywords in C++. In our code, define, include, using, namespace, std, int, main, cin, cout, return are all keywords.
2. Identifier
In C++. identifiers are unique names assigned to variables, functions, classes, objects etc. We will discuss these terms as well as the naming convention of identifiers as we progress further. For now, just remember that in the above code, NUM and n are identifiers.
3. Operator
Operators are special symbols that are used to perform operations on variables, constants or expressions. In the code, <<, >> and + are operators.
4. Constant
Constants are values that do not change once you define them. We define a constant NUM in our code with a value 5. We can also define constants by using the const keyword. For now, just remember that we cannot change its value again.
5. String
String in simple words, is a sequence of characters. For example, your name. In the above code, Hello World is a string which gets printed on the screen. A string is denoted with “”. We will understand strings later when we learn about arrays.
6. Special Symbol
Special symbols are characters that are used for a specific purpose and cannot be used for anything else. In our code, semicolon(;), assignment operator(=), scope resolution(::), double quotes(“), regular () and curly brackets {}, #, <, > and + are all special characters.
That is it for this article. Wishing each and everyone a very happy and prosperous New Year! May this New Year fulfill all your dreams and fill your life with endless happiness and joy.
Let us meet in the next one😀.