**Operators in C++ Tutorial**

Operators in c++ tutorial operator in c,c17 bjarne stroustrup c syntax

Operator are the symbols which perform operation on operands.

**z=x+y;**

Here ,x,y and z are operands and ,+, and ,+, are the operators.

**Operators in c++**

C++ is rich in operators and supports a wide range of these operators that range form the simplest unary to the complex ternary.

Operators are very important because without their use expressions cannot be evaluated.

The following are different types of operators used in C++.

**A. Assignment = operator**

The assignment operator assign a value to a variable.

The symbol= is used as an assignment operator. For Example:

**Vara=55;**

**This statement assign the integer value 55 to the variable Vara.**

the part at the left of the assignment operators= is a variable whereas the right side can be a constant value, a variable, the result of an operators or any combination of these.

The assignment operation always takes place from right to left.

**VarA=VarB;**

**This statement assign the value of variable VarB to VarA.**

consider the following program to demonstrate the use of assignment operator.

#include<iostream.h>

#include<conio.h>

int main()

{

int VaraA, VarB;

VarA=100;

VarB=400;

cout<<"VarA:"<<VarA;

cout<<endl;

cout<<"VarB:"<<VarB;

getch();

return 0;

**Output of the program**

VaraA:100

VarB:400

**B.Arithmetic Operators**

There are five arithmetic operators used in C++.

These are (+,-,*,/,%) that support the following arithmetic operations shown in Table.

**+ Addition**

**_ Subtraction**

*** Multiplication**

**/ Division**

**% Modulus**

The percentage sign % shown in the above table is used for modulus.

Modulus is the operation that gives the reminder of a two values.For example, if we write:

remainder = 11%5;

The variable 'remainder ' will contain the value 1 , since 1 is the remainder from dividing 11 by 5.

The following program demonstrates the use of these operators.

#include<iostream.h>

#include<conio.h>

int main()

{

int a=11, b=5;

int sum=a+b;

int difference=a-b;

int product=a*b;

float division=a/b;

int remaider=a%b;

cout<<"sum="<<sum<<endl;

cout<<"difference="<<difference<<endl;

cout<<"product="<<product<<endle;

cout<<"remainder="<<remainder;

getch();

}

**Out of the program**

sum=16

difference=6

product=55

division=2.0

remainder=1

## No comments:

## Post a Comment