Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of the following statements will post increment the variable by 1 ?

I. a = a + 1; II. a + = 1;
III. a + +; IV. a = + 1;

  • A.Options I, II, III are correct.
  • B.Options II, III, IV are correct.
  • C.Options I, II are correct.
  • D.Options III, IV are correct.

Answer: A

In C, the statements a = a + 1, a += 1 and a++ each add 1 to the variable, so statements I, II and III increment it. The statement a = +1 assigns the value +1 to a and does not increment it, because the plus sign there is a unary operator on the constant 1 and the previous value of a is lost. So the options containing IV are wrong, and the option with only I and II leaves out a++, which is the post increment operator. The answer is that I, II and III are correct.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.