Introduction To C++

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
  1. //using keyword continue    
  2. #include<iostream>  
  3.   
  4. using namespace std;  
  5. int main() {  
  6.     for (int i = 0; I < n; i++)  
  7.         if (i == 3) continue;  
  8.     cout << i << ”\n”;  
  9.     return 0;  
  10. }   
Output
 
Introduction To C++
 

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
  1. //using integer constant    
  2. #include<iostream>  
  3.   
  4. using namespace std;  
  5. int main() {  
  6.     const int length = 10;  
  7.     const int breath = 5;  
  8.     int area;  
  9.     area = length * breath;  
  10.     cout << area;  
  11.     return 0;  
  12. }   
Output
 
Introduction To C++
 
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
  1. //using keyword continue and break    
  2. #include<io stream.h>  
  3.   
  4. using namespace std;  
  5. int main() {  
  6.     cout << ”hello\ tworld\ n\ n”;  
  7.     return o;  
  8. }   
Output
 
Introduction To C++
 

Conclusion

 
In this article, we have seen keywords, identifiers, and constants in C++. I hope this article was useful to you. Thanks for reading! 


Similar Articles