I want to increment a number using the prefix increment operator and then increm
ID: 3529034 • Letter: I
Question
I want to increment a number using the prefix increment operator and then increment the same original number using the postfix increment operator. How would I write the code so that the original value is used both times without having to initialize the number to its original value after the prefix increment operator is implemented? For example, if the number is 5 and I used the prefix increment operator and it becomes 6, and then immediately after I use the postfix increment operator, using the same original number, 5, and then it becomes 6.Explanation / Answer
//once you increment it, using either postfix or prefix, the number would have changed. You'll have //to decrement it right afterward if you do not want it to change
int x=5;
(++x)--; //value would still be 5
x++; //so this will yield 6
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.