TOPIC: C++ Header Files and Operators
C++ Header Files
Let us see how the header files are used:
C++ Program
Code written in Visual Studio Code
// Program to illustrate the use of System header files
#include<iostream> // here, we are using the iostream header files
#include<conio.h> // here, we are using conio.h header files
// we will learn more about the header files, so stay connnected with our blog
using namespace std;
int main()
{
cout<<"We are learning about System header files";
cout<<"Here, iostream and conio.h are used";
getch();
return 0;
}
We are learning about System header files
Here, iostream and conio.h are used
C++ Program
Code written in Visual Studio Code
.cpp file
// Program to illustrate the use of User defined header files
// Make a file with the extension .cpp
#include<iostream>
#include "hellocode.h" // here, a user defined header file is used
using namespace std;
int main()
{
int b = 45;
int c;
cout<<"We are learning about User defined header files";
cout<<"Here, hellocode.h is used";
c = a + b;
cout << c;
return 0;
}
.h file
// Make a file hellocode.h in the same directory
int a = 45;
We are learning about User defined header files
Here, hellocode.h is used
90
Operators
🤔 What do you mean by Operators?
➡️ Operators are the symbols which are used to perform operations (like Addition, Subtraction, Multiplication,
Division, Relational, Logical, etc.) on Operands (like Variables a and b, x and y, newVar, sum, etc.). The
symbols include +, -, *, /, %, ++, --, ==, etc.
These Operators include +, -, *, /, %, ++, --
Example: a + b, a - b
This Operator include =
Example: newVar = 45
These Operators include ==, !=, >=, <=,>, <
Example: a >= b, a < b
These Operators include logical AND (&&), logical OR (||), logical NOT (!)
Example: a &&b, a || b
C++ Program
Code written in Visual Studio Code
// Program to understand the different ytpes of operators
#include<iostream>
using namespace std;
int main()
{
int a = 5, b = 9;
cout << "Operators in C++:" << endl;
cout << "Following are the types of operators in C++:" << endl;
// Arithmetic Operators
cout << "Following are the types of arithmetic operators in C++:" << endl;
cout << "The value of a + b is " << a + b << endl;
cout << "The value of a - b is " << a - b << endl;
cout << "The value of a * b is " << a * b << endl;
cout << "The value of a / b is " << a / b << endl;
cout << "The value of a % b is " << a % b << endl;
cout << "The value of a++ is " << a++ << endl;
cout << "The value of a-- is " << a-- << endl;
cout << "The value of ++a is " << ++a << endl;
cout << "The value of --a is " << --a << endl;
// Assignment Operators
//cout<<"Following are the types of assignment operators in C++:"<< endl;
//int a = 4, b = 5;
//char d ='r';
// Comparison Operators
cout << "Following are the types of comparison operators in C++:" << endl;
cout << "The values of a == b is " << (a == b) << endl;
cout << "The values of a != b is " << (a != b) << endl;
cout << "The values of a >= b is " << (a >= b) << endl;
cout << "The values of a <= b is " << (a <= b) << endl;
cout << "The values of a > b is " << (a > b) << endl;
cout << "The values of a < b is " << (a < b) << endl;
// Logical Operators
cout << "Following are the types logical of operators in C++:" << endl;
cout << "The value of logical AND operator ((a == b) && (a < b)) is " << ((a == b) && (a < b)) << endl;
cout << "The value of logical OR operator ((a == b) || (a < b)) is " << ((a == b) || (a < b)) << endl;
cout << "The value of logical NOT operator (!(a == b)) is " << (!(a == b)) << endl;
return 0;
}
Operators in C++:
Following are the types of operators in C++:
Following are the types of arithmetic operators in C++:
The value of a + b is 14
The value of a - b is -4
The value of a * b is 45
The value of a / b is 0
The value of a % b is 5
The value of a++ is 5
The value of a-- is 6
The value of ++a is 6
The value of --a is 5
Following are the types of comparison operators in C++:
The values of a == b is 0
The values of a != b is 1
The values of a >= b is 0
The values of a <= b is 1
The values of a > b is 0
The values of a < b is 1
Following are the types logical of operators in C++:
The value of logical AND operator ((a == b) && (a < b)) is 0
The value of logical OR operator ((a == b) || (a < b)) is 1
The value of logical NOT operator (!(a == b)) is 1
"First solve the problem. Then, write the code."
- John Johnson
So, we have discussed about the C++ Header Files and Operators. More blogs coming soon.