Defining Your Own Functions
Functions are collections of C++ statements, which are usually fairly short and do some specific thing. These are the two main reasons why functions are essential in programming. I may need hundreds of lines to specify a complex task, and that is simply too long for most humans to follow. It's easy to get lost in big programs, just as in big documents, and you can't assume that your reader has the time or patience to work it out. Dividing code up into functions is like dividing text into named paragraphs and chapters. Programming is like cooking—complicated recipes are broken down into sub-recipes, like making the sauce, cooking the vegetables, etc. The built-in functions like sqrt() are basic steps that all cooks ...
Get C++ By Example: UnderC Learning Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.