Computer Science, asked by naman6418, 10 months ago

WAP to demonstrate the use of increement and decreement operator in c++.

Answers

Answered by ssoouummeenn
1
A program can increment by 1 the value of a variable called c using the increment operator, ++, rather than the expression c=c+1 or c+=1. An increment or decrement operator that is prefixed to (placed before) a variable is referred to as the prefix incrementor prefix decrement operator, respectively.

naman6418: please provide me a hand written program with output in c++ for increement and decreement operator
Answered by jyotigurchan
1


Increment and Decrement Operator in C++

Increment operators are used to increase the value of the variable by one and decrement operators are used to decrease the value of the variable by one.

Both increment and decrement operator are used on single operand or variable, so it is called as unary operator. Unary operators are having higher priority than the other operators it means unary operators are execute before other operators.

Syntax

++ // increment operator -- // decrement operator

Note: Increment and decrement operators are can not apply on constant.

Example

x= 4++; // gives error, because 4 is constant

Type of Increment Operator

pre-increment

post-increment

pre-increment (++ variable)

In pre-increment first increment the value of variable and then used inside the expression (initialize into another variable).

Syntax

++ variable;

Example pre-increment in C++

#include<iostream.h> #include<conio.h> void main() { int x,i; i=10; x=++i; cout<<"x: "<<x; cout<<"i: "<<i; getch(); }

Output

x: 11 i: 11

In above program first increase the value of i and then used value of i into expression.

post-increment (variable ++)

In post-increment first value of variable is use in the expression (initialize into another variable) and then increment the value of variable.

Syntax

variable ++;

Example post-increment

#include<iostream.h> #include<conio.h> void main() { int x,i; i=10; x=i++; cout<<"x: "<<x; cout<<"i: "<<i; getch(); }

Output

x: 10 i: 11

In above program first used the value of i into expression then increase value of i by 1.


jyotigurchan: thnkss for marking as brainliest
Similar questions