Computer Science, asked by Prakhar2908, 1 year ago

What will be the output of a and B, if int a=11; int b = ++a; ?

a.12,11
b.10,10
c.11,12
d.12,12​

Answers

Answered by shardul1925
3
Since,int b= ++a;
So,b=12
and a will be 12 too..


Refer to the attachment u will get it...

So the correct option is (d).


But if there will be a++ then the value of a will be 12 and b will be 11.


Attachments:

Prakhar2908: Thanks bro
shardul1925: wlcm
Answered by siddhartharao77
8

public static void main(String args[])

{

int a = 11, b = ++a;

System.out.println(a);

System.out.println(b);

Output:

12

12

Explanation:

Given, initial value of variable 'a' is 11.

In the above example we have used used pre-increment operator(++a).

In b = ++a, the value of a will be first increased by 1 and then initialize into another expression.

(or)

In b = ++a, the current value(11) is incremented by 1(11 + 1 = 12). The new value of a is then assigned to b.

Hope it helps!


Prakhar2908: Thanks sir
siddhartharao77: Welcome
Similar questions