+ 4
int a=5; int b; b= ++a + ++a; printf("%d", b);
The output to this one is different for Java and C... in C it says 14.. in Java it says 13.... Which is correct? And how does it work?
7 odpowiedzi
+ 11
its all about increment operator.
as in java ++ means +1 and its before a so +1 before a in the initial value
n at every step value changes and at last stored in b
so as a =5
b= 1+a + (1+a)+1//as the changes are made in default value
b=(1+5) + (1+(5+1))
b=6 + 7
b=13//your ans
**this is the program pattern in blue j environment hope it helps you
+ 8
yes 😊😊
+ 3
well I can tell you about C not about Java.
In C all the pre-increments are carried out first:
in this statement we have 2 pre-increaments so your a=5 becomes a=7.
now adding them 7 + 7 is giving you 14.
sorry, but no idea about Java internal expr. evaluation.
+ 3
This might be worth a read:
http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points
In Java ++a is a function with return value a+1, which increases a by 1 as a side effect (while a++ returns a, but has the same side effect).
Hence it would be consistent with the output to assume, that the code is just executed from left to right. Take this with a grain of salt though, I'm not an expert on Java and its internal workings.
0
But the logic of execution has to be same irrespective of the programming language right??
0
Guess answer for the following and then write code to cross check
int a = 1;
Int b =
a++ + ++a + a++ + ++a ;
System.out.print(b);
0
G Sahithi My guess is 12. Is that right? Unable to copy paste this code to compiler. Too lazy to manually copy paste it 😂