Chapter 5: Loops and Files PDF

Summary

This document is chapter 5 of a C++ programming textbook, focusing on loops and files. It provides definitions and examples of loops, increments, and decrements operators and demonstrates how to use files within programs.

Full Transcript

Chapter 5: Loops and Files © Pearson Education Limited 2015 The Increment and Decrement Operators ++ (increment operator) It adds one to a variable. val++; is the same as val = val + 1; ++ can be used before (prefix) or after (postfix) a variable: ++val; val++...

Chapter 5: Loops and Files © Pearson Education Limited 2015 The Increment and Decrement Operators ++ (increment operator) It adds one to a variable. val++; is the same as val = val + 1; ++ can be used before (prefix) or after (postfix) a variable: ++val; val++; © Pearson Education Limited 2015 The Increment and Decrement Operators -- (decrement operator) It subtracts one from a variable. val--; is the same as val = val - 1; -- can be also used before (prefix) or after (postfix) a variable: --val; val--; © Pearson Education Limited 2015 Prefix vs. Postfix ++ and -- operators can be used in complex statements and expressions In prefix mode (++val, --val)the operator increments or decrements, then returns the value of the variable In postfix mode (val++, val--) the operator returns the value of the variable, then increments or decrements © Pearson Education Limited 2015 Prefix vs. Postfix - Examples int num, val = 12; cout

Use Quizgecko on...
Browser
Browser