define the increment and decrement operators


 

Define the Increment and Decrement Operators in c language?

C offers two special operators -and ++ called decrement and increment operators respectively and these are unary operators since they operate on only one operand and the operand has to be variable not a constant. Therefore the expression a++ is valid where as 5++ isn't and the operator ++ adds 1 to the operand while - subtracts 1. a++ and ++a mean the same thing when they are used alone in statements but they behave differently when they are used in expressions on the right hand side of an assignment statement.

Consider the following

x=100;
y=++x;

In this case, the value of X and Y would be 101.

If we rewrite it as y=x++ and x=100 then the value of y=100and x=101. A prefix operator first adds 1 to the operand and after that the result is assigned to the variable on the left. On the other side a postfix operator first assigns the value to the variable on left and then increments the operand.

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: define the increment and decrement operators
Reference No:- TGS0304654

Expected delivery within 24 Hours