Computer Science, asked by balharpreetkaur23, 1 year ago

What will be the output of the following program segment?
int a = 10;
int b = 30;
int c = 40;
a = b-- + c - a % 2;
System.out.println(“a”+a);
System.out.println(“b”+b);

Answers

Answered by anupama777vidya
3

Answer:

a70

b29

Explanation:

a=30+40-10%2

Follow BODMAS rule,

a=30+40-0=70.

I hope u know the difference between postfix and prefix.

Well,in postfix(a++),we follow UTC(Use Then Change)method.

In prefix(++a),we follow CTU(Change Then Use)method.

So applying this in b--,b turns out to be 29 AFTER the operation.

Hope I'm clear...

Answered by gitishgodwingj
0

Answer: 98

Explanation:

The --b is a pre-decrement operator. It decrements value of B by 1 before calculating.

So, b becomes 29 in calculation.

The c++ is a post increment operator. It increments the value of c by 1 after calculation. So in our case, c still remains 40

So, a= 29+40+29

a=98

So, answer is 98

Similar questions