Header files & Operators in C++
// There are two types of header files:
// 1. System header file: It comes with the compiler
#include<iostream>
// 2. User defined header file: It is written by the programmer
// #include"this.h" This will produce an error if this.h is not present in the current directory
using namespace std;
int main()
{
int a=4,b=5;
cout<<"Operators in C++ : "<<endl;
cout<<"Following are the types of operators in C++"<<endl;
//Arithmetic Operators
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;
cout<<endl;
//Assignment operators --> used to assign values to variables
// int a=3,b=9;
// char d='d';
//Comparison operators
cout<<"Following are the comparison 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 <= b is : "<<(a <= b)<<endl;
cout<<endl;
//Logical operators
cout<<"Following are the logical operators in C++"<<endl;
cout<<"The value of this logical AND operator ((a==b) && (a<b)) is : "<<((a==b) && (a<b))<<endl;
cout<<"The value of this logical OR operator ((a==b) || (a<b)) is : "<<((a==b) || (a<b))<<endl;
cout<<"The value of this logical NOT operator (!(a==b)) is : "<<(!(a==b))<<endl;
return 0;
}
OUTPUT:
> cd "d:\C++\" ; if ($?) { g++ tut6.cpp -o tut6 } ; if ($?) { .\tut6 }
Operators in C++ :
Following are the types of operators in C++
The value of a + b is : 9
The value of a - b is : -1
The value of a * b is : 20
The value of a / b is : 0
The value of a % b is : 4
The value of a++ is : 4
The value of a-- is : 5
The value of ++a is : 5
The value of --a is : 4
Following are the comparison operators in C++
The value of a==b is : 0
The value of a!=b is : 1
The value of a > b is : 0
The value of a < b is : 1
The value of a >= b is : 0
The value of a <= b is : 1
Following are the logical operators in C++
The value of this logical AND operator ((a==b) && (a<b)) is : 0
The value of this logical OR operator ((a==b) || (a<b)) is : 1
The value of this logical NOT operator (!(a==b)) is : 1
PS D:\C++>
Comments
Post a Comment