You are currently viewing 50 Best MCQs on Increment and Decrement Operators in Java
MCQs on Increment and Decrement

50 Best MCQs on Increment and Decrement Operators in Java

  • Post author:
  • Post last modified:December 28, 2023
  • Reading time:27 mins read

MCQs on Increment and Decrement Operators in Java: These operators are “++” and “–“ respectively. This two-operator increases or decreases the value of a variable by 1. While they may seem simple at first glance, understanding their behavior and usage is crucial for writing efficient and error-free code. Here we have compiled the 50 best multiple-choice questions (MCQs) that cover various aspects of increment and decrement operators in Java. Whether you are a beginner looking to strengthen your understanding of these operators or an experienced developer seeking to brush up on your knowledge, these MCQs will test your proficiency and provide valuable insights.

The MCQs in this compilation are designed to cover a wide range of scenarios, including basic concepts, pre- and post-increment/decrement, operator precedence, side effects, and compound assignments. We were given a question followed by 4 multiple options. Guess the right answer and see your result by clicking the View Answer button. The answer is given with an explanation. By attempting these MCQs, you will not only enhance your knowledge of increment and decrement operators but also gain a deeper understanding of their behavior in different contexts. Additionally, the explanations provided for each question will help you grasp the underlying concepts and reasoning behind the correct answers.

Whether you are preparing for a Java certification exam or simply aiming to improve your programming skills, these MCQs will serve as a valuable resource. So, let’s dive into the world of increment and decrement operators in Java and test your expertise with these 50 best MCQs.

Introduction to Java Programming

Best 50 Java Multiple-Choice Questions to Test Your Skills, and Boost Your Knowledge

The Best 50 MCQ on C Language with Answers

Java MCQ
Java MCQ

MCQs on Increment and Decrement Operators

1. What is the result of the expression int x = 5; x++;?
a) x is still 5
b) x is now 6
c) x is now 4
d) Compilation error

2. Which operator is used for incrementing a variable by 1 in Java?
a) +=
b) ++
c) —
d) *=

3. What will be the value of int y = 10; y–;?
a) 9
b) 10
c) 11
d) 8

4.What does the expression int z = 7; z = z++ + ++z; evaluate to?
a) 14
b) 15
c) 16
d) Compilation error

5. What is the value of int a = 3; a = a++ + a–;?
a) 6
b) 7
c) 8
d) 9

6. What is the output of the following code snippet?

int b = 2;
System.out.println(++b + b++);
a) 4
b) 5
c) 6
d) 7

7. Which of the following statements is true about the post-increment operator in Java?
a) It increments the value before using it in an expression.
b) It increments the value after using it in an expression.
c) It does not exist in Java.
d) It decrements the value.

8.What will be the value of int c = 5; c = c++ + ++c;?
a) 11
b) 12
c) 13
d) 14

9. What is the output of the following code snippet?

int d = 3;
System.out.println(d++ + ++d – d–);
a) 2
b) 3
c) 4
d) 5

10.What is the purpose of the decrement operator — in Java?
a) To subtract a value from a variable
b) To decrease the value of a variable by 1
c) To negate the value of a variable
d) To divide a variable by 2

MCQs on Increment and Decrement
MCQs on Increment and Decrement

11. Which of the following is a valid use of the increment operator?
a) int result = 2 * x++;
b) int result = x– / 2;
c) int result = x++ + –x;
d) int result = x++ * x–;

6 Best C Programming Language Books

12. If int i = 5; and int j = ++i;, what is the value of j?
a) 4
b) 5
c) 6
d) 7

13. What is the output of the following code snippet?

int m = 2;
System.out.println(m++ + m– – ++m);
a) 0
b) 1
c) 2
d) 3

14. Which of the following is equivalent to x = x + 1;?
a) x++
b) ++x
c) x–
d) –x

15.What is the result of the expression int n = 8; n = n– – –n;?
a) 0
b) 1
c) 2
d) 3

16. In Java, what is the difference between the pre-increment and post-increment operators?
a) There is no difference.
b) Pre-increment increments the value before using it, while post-increment increments the value after using it.
c) Pre-increment increments the value after using it, while post-increment increments the value before using it.
d) Pre-increment and post-increment cannot be used interchangeably.

17.What will be the value of int p = 4; p = p– + ++p – p++;?
a) 5
b) 6
c) 7
d) 8

18. What is the output of the following code snippet?
int q = 3;
System.out.println(q– + q++ + –q);
a) 6
b) 7
c) 8
d) 9

19. What happens if you attempt to increment a variable of type char using the ++ operator?
a) It is not allowed, and it results in a compilation error.
b) The character is incremented by 1.
c) The ASCII value of the character is incremented by 1.
d) The variable becomes null.

20.What is the value of int r = 5; r += r++ – –r;?
a) 5
b) 6
c) 7
d) 8

Java Interview Questions with Answers
Java Interview Questions with Answers

21. Which of the following is a valid use of the decrement operator?
a) int result = –x + x++;
b) int result = x++ * –x;
c) int result = x– / 2;
d) int result = 2 * x–;

22. What is the output of the following code snippet?
int s = 4;
System.out.println(s++ + s– + ++s);
a) 9
b) 10
c) 11
d) 12

23. If int t = 7; and int u = t–;, what are the values of t and u?
a) t = 6, u = 6
b) t = 6, u = 7
c) t = 7, u = 6
d) t = 7, u = 7

24. What is the output of the following code snippet?
int v = 3;
System.out.println(++v – v– + v++);
a) 4
b) 3
c) 2
d) 1

25. Which of the following expressions is equivalent to x = x + 1; in Java?
a) x += 1;
b) x =+ 1;
c) x = x++;
d) x = x–;

26. What will be the value of int w = 6; w = –w + w– + ++w;?
a) 12
b) 13
c) 14
d) 15

27. What does the expression int x = 2; x = x++ + x; evaluate to?
a) 2
b) 3
c) 4
d) 5

28. What is the result of the expression int y = 4; y = y++ – –y;?
a) 0
b) 1
c) 2
d) 3

29. What is the output of the following code snippet?
int z = 5;
System.out.println(z++ + z++ + z++);
a) 15
b) 16
c) 17
d) 18

30. If int a = 8; and int b = a–;, what are the values of a and b?
a) a = 7, b = 8
b) a = 7, b = 7
c) a = 8, b = 7
d) a = 8, b = 8

Java Multiple-Choice Questions
MCQs on Increment and Decrement

31. What is the output of the following code snippet?
int c = 6;
System.out.println(c– – c++ + ++c);
a) 11
b) 12
c) 13
d) 14

32. Which of the following expressions is equivalent to x = x – 1; in Java?
a) x -= 1;
b) x =- 1;
c) x = x–;
d) x = x++;

33. What will be the value of int d = 3; d = d– – ++d + d–;?
a) 0
b) 1
c) 2
d) 3

34. What does the expression int e = 4; e = e– + e; evaluate to?
a) 4
b) 5
c) 6
d) 7

35. What is the output of the following code snippet?
int f = 2;
System.out.println(f– + f++ – –f);
a) 2
b) 3
c) 4
d) 5

36. If int g = 9; and int h = g++;, what are the values of g and h?
a) g = 9, h = 9
b) g = 9, h = 10
c) g = 10, h = 9
d) g = 10, h = 10

37. What is the result of the expression int i = 5; i = i++ – –i + ++i;?
a) 9
b) 10
c) 11
d) 12

38. What will be the value of int j = 4; j = j++ + –j – j–;?
a) 1
b) 2
c) 3
d) 4

39. What is the output of the following code snippet?
int k = 7;
System.out.println(k++ + ++k – k–);
a) 14
b) 15
c) 16
d) 17

40. Which of the following statements is true about the post-decrement operator in Java?
a) It decrements the value before using it in an expression.
b) It decrements the value after using it in an expression.
c) It does not exist in Java.
d) It increments the value.

41.What will be the value of int l = 5; l += l– + ++l;?
a) 10
b) 11
c) 12
d) 13

42. What is the output of the following code snippet?
int m = 3;
System.out.println(m– – ++m + m++);
a) 1
b) 2
c) 3
d) 4

43. If int n = 6; and int o = –n;, what are the values of n and o?
a) n = 5, o = 6
b) n = 5, o = 5
c) n = 6, o = 5
d) n = 6, o = 6

44. What is the output of the following code snippet?
int p = 4;
System.out.println(p++ – –p + ++p);
a) 8
b) 9
c) 10
d) 11

45. What happens if you attempt to decrement a variable of type double using the — operator?
a) It is not allowed, and it results in a compilation error.
b) The double value is decremented by 1.
c) The variable becomes null.
d) The variable is rounded to the nearest integer.

46. What is the value of int q = 8; q = q– – ++q + q–;?
a) 12
b) 13
c) 14
d) 15

47. What is the output of the following code snippet?
int r = 5;
System.out.println(r++ – –r + r++);
a) 10
b) 11
c) 12
d) 13

48. If int s = 10; and int t = s–;, what are the values of s and t?
a) s = 9, t = 10
b) s = 9, t = 9
c) s = 10, t = 9
d) s = 10, t = 10

49. What is the output of the following code snippet?
int u = 6;
System.out.println(u– + ++u – u++);
a) 12
b) 13
c) 14
d) 15

50. Which of the following expressions is equivalent to x = x – 1; in Java?
a) x -= 1;
b) x =- 1;
c) x = x–;
d) x = x++;

MCQs Answer: MCQs on Increment and Decrement

Answer to Increment and Decrement Operators

  1. Answer: b) x is now 6
    • Explanation: The post-increment operator x++ increments the value of x after it is used in the expression. Therefore, x becomes 6 after the statement.
  2. Answer: b) ++
    • Explanation: The increment operator ++ is used for incrementing a variable by 1 in Java.
  3. Answer: a) 9
    • Explanation: The post-decrement operator y-- decreases the value of y after it is used in the expression. Therefore, y becomes 9 after the statement.
  4. Answer: b) 15
    • Explanation: z++ increments z after it is used, and ++z increments z before it is used. So, z is used twice with different values, resulting in 15.
  5. Answer: b) 7
    • Explanation: The post-increment and post-decrement operators both use the current value before updating. Therefore, the expression evaluates to 7.
  6. Answer: c) 6
    • Explanation: ++b increments b before it is used, and b++ increments b after it is used. So, the expression evaluates to 6.
  7. Answer: b) It increments the value after using it in an expression.
    • Explanation: The post-increment operator increments the value after it has been used in an expression.
  8. Answer: a) 11
    • Explanation: The post-decrement and pre-increment operators are used, resulting in the value 11.
  9. Answer: c) 4
    • Explanation: The post-decrement and post-increment operators are used, resulting in the value 4.
  10. Answer: b) To decrease the value of a variable by 1
    • Explanation: The decrement operator -- is used to decrease the value of a variable by 1 in Java.
  11. Answer: c) int result = x++ + --x;
    • Explanation: This expression uses both post-increment and pre-decrement operators.
  12. Answer: c) 6
    • Explanation: The pre-increment operator ++i increments the value of i before it is assigned to j.
  13. Answer: b) 1
    • Explanation: The post-increment and post-decrement operators are used, resulting in the value 1.
  14. Answer: a) x++
    • Explanation: The post-increment operator x++ is equivalent to x = x + 1;.
  15. Answer: b) 1
    • Explanation: The post-decrement and pre-decrement operators are used, resulting in the value 1.
  16. Answer: b) Pre-increment increments the value before using it, while post-increment increments the value after using it.
    • Explanation: Pre-increment increments the value before it is used in an expression, while post-increment increments the value after it is used.
  17. Answer: b) 6
    • Explanation: The post-decrement, pre-increment, and post-increment operators are used, resulting in the value 6.
  18. Answer: d) 9
    • Explanation: The post-decrement and pre-increment operators are used, resulting in the value 9.
  19. Answer: a) It is not allowed, and it results in a compilation error.
    • Explanation: The decrement operator cannot be used with variables of type char in Java.
  20. Answer: b) 6
    • Explanation: The post-decrement, post-increment, and pre-increment operators are used, resulting in the value 6.
  21. Answer: c) int result = x-- / 2;
    • Explanation: This expression uses the post-decrement operator.
  22. Answer: b) 10
    • Explanation: The post-increment, post-decrement, and pre-increment operators are used, resulting in the value 10.
  23. Answer: c) t = 7, u = 6
    • Explanation: The post-decrement operator is used in the assignment, so the value of t is the current value of s (before decrementing).
  24. Answer: a) 4
    • Explanation: The pre-increment, post-decrement, and post-increment operators are used, resulting in the value 4.
  25. Answer: a) x += 1;
    • Explanation: The compound assignment operator += is equivalent to x = x + 1;.
  26. Answer: a) 12
    • Explanation: The pre-decrement, post-decrement, and pre-increment operators are used, resulting in the value 12.
  27. Answer: c) 4
    • Explanation: The post-increment and post-decrement operators are used, resulting in the value 4.
  28. Answer: b) 1
    • Explanation: The post-increment and pre-decrement operators are used, resulting in the value 1.
  29. Answer: c) 17
    • Explanation: The post-increment operator is used three times, resulting in the value 17.
  30. Answer: a) a = 7, b = 8
    • Explanation: The post-decrement operator is used in the assignment, so the value of b is the current value of a (before decrementing).
  31. Answer: b) 12
    • Explanation: The post-decrement, pre-increment, and post-increment operators are used, resulting in the value 12.
  32. Answer: a) x -= 1;
    • Explanation: The compound assignment operator -= is equivalent to x = x - 1;.
  33. Answer: c) 2
    • Explanation: The post-decrement, pre-increment, and post-decrement operators are used, resulting in the value 2.
  34. Answer: c) 6
    • Explanation: The post-decrement and post-increment operators are used, resulting in the value 6.
  35. Answer: a) 2
    • Explanation: The post-decrement, post-increment, and pre-decrement operators are used, resulting in the value 2.
  36. Answer: a) g = 9, h = 10
    • Explanation: The post-decrement operator is used in the assignment, so the value of h is the current value of g (before decrementing).
  37. Answer: c) 11
    • Explanation: The post-decrement, pre-increment, and post-increment operators are used, resulting in the value 11.
  38. Answer: a) 1
    • Explanation: The post-increment, pre-decrement, and post-decrement operators are used, resulting in the value 1.
  39. Answer: c) 16
    • Explanation: The post-increment operator is used three times, resulting in the value 16.
  40. Answer: b) It decrements the value after using it in an expression.
    • Explanation: The post-decrement operator decrements the value after it has been used in an expression.
  41. Answer: c) 12
    • Explanation: The post-decrement, post-increment, and pre-increment operators are used, resulting in the value 12.
  42. Answer: a) 1
    • Explanation: The post-decrement, pre-increment, and post-increment operators are used, resulting in the value 1.
  43. Answer: d) n = 6, o = 6
    • Explanation: The post-decrement operator is used in the assignment, so the value of o is the current value of n (before decrementing).
  44. Answer: b) 9
    • Explanation: The post-decrement, pre-increment, and post-increment operators are used, resulting in the value 9.
  45. Answer: a) It is not allowed, and it results in a compilation error.
    • Explanation: The decrement operator cannot be used with variables of type double in Java.
  46. Answer: a) 12
    • Explanation: The post-decrement, pre-decrement, and post-increment operators are used, resulting in the value 12.
  47. Answer: a) 10
    • Explanation: The post-decrement, pre-increment, and post-increment operators are used, resulting in the value 10.
  48. Answer: d) s = 10, t = 10
    • Explanation: The post-decrement operator is used in the assignment, so the value of t is the current value of s (before decrementing).
  49. Answer: c) 14
    • Explanation: The post-decrement, pre-increment, and post-increment operators are used, resulting in the value 14.
  50. Answer: a) x -= 1;
    • Explanation: The compound assignment operator -= is equivalent to x = x - 1;.

Khurshid Anwar

I am a computer science trainer, motivator, blogger, and sports enthusiast. I have 25 years of training experience of Computer Science, Programming language(Java, Python, C, C++ etc).