- 7

If a=10 b= a++ + ++a what is b?

24th Nov 2016, 2:40 PM
Divya rao
Divya rao - avatar
22 Respuestas
+ 18
Well, its 22. Try it yourself before down voting this answer. From first term of the expression b=a++ + ++a; a++ means 10 but it will increase it value if it is use again. ++a means increase value of a immediately. What is value of a. It is 10, no it will change it value by 1 if it use again. So from above line its value is 11 and than increase value of a immediately its value is 12. So value of b = 22. Use this below code public class Program { public static void main(String[] args) { int a=10,b; b= a++ + ++a; System.out.println(b); } }
24th Nov 2016, 3:04 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 3
var++ gives the current value first then increments it by 1. ++var increments the value by 1 first then gives its value. so in your question: a = 10; current value of a is 10. a++ gives the current value first which is 10, then makes its value 11. so the current value of a is 11. ++a increments 11 by 1 first, making a = 12, then gives its current value which is 12. so, b = a++ + ++a = 10 + 12 = 22
1st Jan 2017, 5:21 PM
Erwin Mesias
Erwin Mesias - avatar
+ 1
10+12 = 22
24th Nov 2016, 5:40 PM
Dhruv Saxena
Dhruv Saxena - avatar
+ 1
b=a++ + ++a; equal a=1+a; b=a+a; a=1+a; soo b=22
28th Nov 2016, 3:30 PM
mohamad.khalili
+ 1
b = 22
28th Nov 2016, 11:04 PM
Mohammad Zarchi
Mohammad Zarchi - avatar
+ 1
a++ : increment after assign value. ++a : assign value after increment.
12th Dec 2016, 1:06 AM
Ritesh Patidar
Ritesh Patidar - avatar
+ 1
b=22 because it is incremented twice.
9th Dec 2017, 5:17 PM
Zacharias King
Zacharias King - avatar
+ 1
(++a)+(a++)
5th Oct 2018, 4:29 PM
Policherla Sirisha
+ 1
Here in this example ++a (prefix) having first priority over a++ (postfix) , so according to this rules first evaluates ++a so a = 11 now after assigning the evaluated values of a++ + ++a to b so 11 + 11 = 22 = b. then post increment operator will executes in last so the value of a again incremented, at the end of evaluation is a =12 , b = 22.
2nd Aug 2019, 12:09 PM
Latesh Parmar
Latesh Parmar - avatar
+ 1
What will be ++a + a++
25th Mar 2020, 12:10 PM
Pramod Bogi
Pramod Bogi - avatar
0
22 is the answer for better practice use code playground
24th Nov 2016, 3:05 PM
Shayan
Shayan - avatar
0
22
26th Nov 2016, 2:45 PM
shadowWhite
shadowWhite - avatar
0
22 refer post and pre fix operators
27th Nov 2016, 5:30 PM
SAKET upadhyay
SAKET upadhyay - avatar
0
22
28th Nov 2016, 5:21 PM
ZEKROM
0
according 2 my analysis in a single equ. same variable don't hv different values from 1 st a++ = 10 but from 2nd ++a it become 11 know in equ is b= a++ + ++a; bt their is 2 values of a so, it will use the lst update value of a which is 11 both the a become a =11 if u want 2 check so chk for this qust b= a + ++a; its also give 22
29th Nov 2016, 6:12 PM
Som Keshri
Som Keshri - avatar
0
Now try b=a+++a; //a is initially 10
29th Nov 2016, 6:59 PM
Vaibhav
0
++a++
1st Nov 2018, 4:46 AM
Parmar Rahul
0
14
24th Apr 2020, 5:53 AM
kambhampati ramakrishna
kambhampati ramakrishna - avatar
2nd Oct 2020, 8:13 AM
Prantik Sarkar
Prantik Sarkar - avatar
0
class OperatorExample { public static void main(String args[]) { int a = 10 ; int b = 10 ; System.out.println(a++ +++a); //10+12=22 System.out.println(b+++b++); // 10 + 11 = 21 }} ans plz in details?
22nd Mar 2023, 5:46 AM
Rudra Das
Rudra Das - avatar