You are on page 1of 4

LAB ASSIGNMENT # 2

Arithmetic Assignment Operator :


C++ offers several ways to shorten and clarify your codes one of these is Arithmetic Assignment Operator. This operator help to give C++ listing their appearance .The following king of statement is common in most languages. Its syntax is; Total=Total + Item In this situation we add something to an existing value but the syntax of this statement cause the name Total to appear twice. So C++ offers a unique approach the Arithmetic Assignment Operator Which an arithmetic operator and assignment operator. Example: Total + = Item Total - = Item Total * = Item Total / = Item

Implementing a Simple Program:


#include<iostream.h> #include<conio.h> Void main(void) { Clrscr(); Int a=5; Cout<<a+=5<<(a+=5)<<endl; Cout<<a-=5<<(a-=5)<<endl; Cout<<a*=5<<(a*=5)<<endl; Cout<<a/=5<<(a/=5)<<endl; Getche(); }

Increment Operator:
The operator that is used to add 1 (one) to the value of a variable is called increment operator. It is used to add 1 (one) to the value of an integer variable. This operator can be used before or after the variable name. To add 1 (one) to a value of variable Total, increment operator can be written either before or after the variable.

Types of Increment Operator:


The increment operator can be used in two ways as: i) ii) Prefix Increment Operator Postfix Increment operator When an increment operator is used in prefix mode in an expression, it add 1 (one) to the value of the variable before the value of the variable is used in the expression. For Example:
#include<iostream.h> #include<conio.h> Void main(void) { Clrscr(); Int a=10; Cout<<a<<endl; Cout<<++a<<endl; Cout<<a<<endl; Getche(); }

1. Prefix Increment operator :

2. Postfix Increment operator:


When an increment operator is used in postfix mode in an expression, it adds 1 (one) to the value of variable after the value of the variable has been used in the expression. For Example:

#include<iostream.h> #include<conio.h> Void main(void) { Clrscr(); Int a=10; Cout<<a<<endl; Cout<<a++<<endl; Cout<<a<<endl; Getche(); }

The Decrement Operator:


The operator that is used to subtract 1 (one) from the value of a variable is called decrement operator. For Example to subtract 1 (one) from the value of a variable count, the decrement statement is written as:

Types of Decrement Operator:


i) ii) Prefix Decrement operator. Postfix Decrement Operator.

1. Prefix Decrement operator:


When a decrement operator is used in prefix mode in an expression. It subtracts 1 (one) from the value of the variable before the value of the variable is used in the expression. For Example:
#include<iostream.h> #include<conio.h> Void main(void) { Clrscr(); Int a=10; Cout<<a<<endl; Cout<<--a<<endl; Cout<<a<<endl; Getche(); }

2. Postfix Decrement Operator:


When a decrement operator is used in postfix mode in an expression, it subtract 1 (one) from the value of the variable after the value of the variable has been used in the expression.

For Example:
#include<iostream.h> #include<conio.h> Void main(void) { Clrscr(); Int a=10; Cout<<a<<endl; Cout<<a--<<endl; Cout<<a<<endl; Getche(); }

You might also like