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;
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.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development