Computer Applications
Give the output of the following expression, when a = 6.
a += ++a + a++ + a-- + a-- + --a + ++a
Answer
The output will be 46.
Explanation
a += ++a + a++ + a-- + a-- + --a + ++a [a = 6]
a = a + (++a + a++ + a-- + a-- + --a + ++a) [a = 6]
a = 6 + (7 + a++ + a-- + a-- + --a + ++a) [a = 7]
a = 6 + (7 + 7 + a-- + a-- + --a + ++a) [a = 8]
a = 6 + (7 + 7 + 8 + a-- + --a + ++a) [a = 7]
a = 6 + (7 + 7 + 8 + 7 + --a + ++a) [a = 6]
a = 6 + (7 + 7 + 8 + 7 + 5 + ++a) [a = 5]
a = 6 + (7 + 7 + 8 + 7 + 5 + 6) [a = 6]
a = 6 + 40
a = 46
Related Questions
State the method that
(a) converts a string to a primitive float data type.
(b) determines if the specified character is an uppercase character.
Predict the output of the following.
(a) Math.pow(2.5, 2) + Math.ceil(5)
(b) Math.round(2.9) + Math.log(1)
Write a program to input a number. Check and display whether it is a Niven number or not. (A number is said to be Niven which is divisible by the sum of its digits).
Example: Sample Input 126
Sum of its digits = 1 + 2 + 6 = 9 and 126 is divisible by 9.