© Mikael Olsson 2020
M. OlssonC++20 Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-5995-5_11

11. Functions

Mikael Olsson1 
(1)
Hammarland, Finland
 

Functions are reusable code blocks that will only execute when called.

Defining Functions

A function can be created by typing void followed by the function’s name, a set of parentheses, and a code block. The void keyword means that the function will not return a value. A common naming convention for functions is to name them in the same way as variables—a descriptive name with each word initially capitalized, except for the first one.
#include <iostream>
using namespace std;
void myFunction()
{
  cout << "Hello World";
}

Calling Functions

The previous function will simply print out a text message when ...

Get C++20 Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library 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.