Get the FREE certificate on C, C++, Java, Python, Perl, PHP, SQL, Linux & Javascript!  

CppBuzz.com
  
Home C C++ Java Python Perl PHP Spring SQL Javascript Linux
< class="locationheader">You are here : Home » Program on operators

C++ program on operators

Arithmetic Operators Example in C++

#include <iostream>
using namespace std;

int main ()
{
  int a, b;         
  a = 10;           
  b = 5;       

  cout << "a + b :" << a + b;
  cout << "a * b : "<< a * b;
  cout << "a - b: "<< a - b;
  cout << "a / b: "<< a / b;
   
  cout <<" ++a is : "<< ++a;
  cout <<" --a is : "<< --a;
  
  return 0;
}

Relational Operators Example in C++

 
#include <iostream>
using namespace std;

int main ()
{
  int a, b ,c;
  cin>>a>>b>>c;
 
  if(a > b && a > c)
  { cout<<"\n a is biggest no ";
  }	  
  else if(b > c && b > a)
  {cout<<"\n b is biggest no ";
  }
  else if(c > a && c >b)
  {
	  cout<<"\n c is biggest no ";
  }
  else
  {cout<<"\n All no are equal ";
  }
  return 0;
}

Logical Operators Example in C++

 
#include <iostream>
using namespace std;

int main ()
{
  int a, b ,c;
  cin>>a>>b>>c;
 
  if(a > 0  || b > 0 || c> 0)
  { cout<<"\n One of them is greater than 0 ";
  }	  

  return 0;
}

Bitwise Operators Example in C++

 
#include <iostream>
using namespace std;

int main ()
{
int a, b ;
a = 0;
b = 1;
cout<<" a | b" << a|b;
cout<<" a & b" << a&b;
cout<<" ~a" << ~a;
  
return 0;
}

Assignment operator Example in C++


#include <iostream>
using namespace std;

int main ()
{
  int a, b;         
  a = 10;           
  b = 4;            
  a = b;            
  b = 7;            

  cout << "a:";
  cout << a;
  cout << " b:";
  cout << b;
  
  return 0;
}

Assignment operator Example 2 in C++

#include <iostream>
using namespace std;

int main ()
{
  int a;       
  a = 10;           
  a += 5;
  cout<<" a = a + 5 :"<< a;         

  return 0;
}

Conditional operator Example in C++

#include <iostream>
using namespace std;

int main ()
{
  int a,b,c;

  a=2;
  b=7;
  c = (a>b) ? a : b;

  cout << c << '\n';
}

Size of Operator Example in C++ (Miscellaneous Operator)

#include <iostream>
using namespace std;

int main ()
{
  int a,b,c;

  a=2;
  b=7;
  c = (a>b) ? a : b;

  cout << c << '\n';
}