Computer Science, asked by pankajtrivedi222, 6 months ago

use following expression:
a = a++ + -- b + c ++;

Answers

Answered by kulkarninishant346
1

In implementation, when we require to change the initial value of the variable by 1, then go for increment/decrement operators. I.e “++,--“

When we are working with increment / decrement operator the difference b/w existing value and new value is +1 and -1 only.

Depending on the position, these operators are classified into two types.

i.e pre & post operators.

When the symbol is available before the operand, then it is called pre-operator, if the symbol is available after the operand, then it is called post operator

When we are working with pre operators, data need to be modified before evaluating the expression

When we are working with post operators, data need to be modified after evaluating the expression

Syntax :-

First increment the value of “a” by 1 and then evaluate the expression i.e, b=1;

Int a,b;

A=1;

Syntax1:

b=++a; pre increment

i.e b=a;

o/p: a=2 b=2

First evaluate the expression and then increment the value of “ a “ by 1

Syntax 2 :-

b=a++, post increment

o/p: a=2 b=1

First decrement the value of “a” by 1 and then evaluate the expression

Syntax 3 : -

b=-a; pre decrement

o/p : a=0 b=0.

First evaluate the expression , later decrement the value of a by 1

Syntax 4:

b=a - -, post decrement

B=1, a=0

Void main()

{

Int a;

A=10;

++a; || a=a+1;

Printf(“a=%d”,a);

}

o/p: a=11

void main()

{

Int a;

A=10;

A++; || a=a+1;

Printf(“a=%d”,a);

}

o/p: a=11

Until we are not assigning the data to any other variable, there is no difference b/w pre and post operators.

Void main() a=++a + ++a + ++a

{ a=a+a+a

Int a; a=4+4+4

A=1; all should be evaluated at a time

A=++a + ++a + ++a;

Printf("a=%d”,a);

}

o/p: 12

( )

+,-,!,++,-- pre

*,/,%

+,-

<,>,<=,>=

==,!=

&&

||

?:

=

++,--,post

Void main()

a=++a + a++ + ++a

{ a= a+a+a

Int a; 3+3+3

A=1; 9

A=++a +a ++ + ++a;

Printf(“a2%d”,a);

}

A=10;

Void main()

{

Int a;

A=1; a+a+a

A=a++ + ++a + a++; 2+2+2 a=6

Printf(“a=%d”,a); =6 a++ =7

o/p: a=8; and a++ - 7+1=8

Similar questions