Introduction
In this article, I will explain the keywords, identifiers, constants in C++.
C++ was developed at AT&T Bell lab in the early 1980s by Bjarne Stroustrup. The name C++ was coined by Rick Mascitti where "++" is the C increment operator.
Keywords
Keywords have special meaning to the language compiler. These are reserved words for special purposes. These reserved words are can’t be used as normal identifiers.
A list of some keywords used in C++:
- auto
- break
- case
- const
- class
- continue
- default
- delete….
Example Program
-
- #include<iostream>
-
- using namespace std;
- int main() {
- for (int i = 0; I < n; i++)
- if (i == 3) continue;
- cout << i << ”\n”;
- return 0;
- }
Output
Identifiers
These are also known as variables. Identifiers are memory boxes that hold constants or values. The identifiers or variables must begin with an underscore or alphabet and it followed by alphabets or numbers.
Let's see an example:
_test, test, sum123….
Constants
Constants are data items whose value cannot be changed. It has two types, numeric or non-numeric type. Numeric constants consist of only numbers. These are decimal, floating, whole, or integer.
Integer Constant
An integer constant must have at least one digit and must not contain any fractional part.
Example Program
-
- #include<iostream>
-
- using namespace std;
- int main() {
- const int length = 10;
- const int breath = 5;
- int area;
- area = length * breath;
- cout << area;
- return 0;
- }
Output
Floating Point Constant
A floating-point constant is signed real numbers. It includes an integer portion a decimal point, a fractional portion, and an exponent.
Character Constant
A character constant is a constant that contains a single character enclosed within single quotes. Certain special characters like tab, backspace, lines feed, null, blackslash are called non-graphic character constants. These characters are represented using escape sequences.
Some escape sequences are:
- \a - bell
- \b - back space
- \n - new line
- \o - octal number
- \x - hexadecimal number
- \0 - null
Example Program
-
- #include<io stream.h>
-
- using namespace std;
- int main() {
- cout << ”hello\ tworld\ n\ n”;
- return o;
- }
Output
Conclusion
In this article, we have seen keywords, identifiers, and constants in C++. I hope this article was useful to you. Thanks for reading!