Calling Functions

In the previous exercise, you might have noticed that when we define a function and run the code, nothing happens. That's because the function only runs when we call it. We call a function using its name followed by parentheses. For example, if we have a function defined as follows:

void myFunction() {
    std::cout << "This is my function" << std::endl;
}

We can call it in the following way:

myFunction(); // Prints: This is my function

When we call a function, its body is executed. In this case, This is my function is printed. Functions can be called repeatedly and whenever needed within a program.

Instructions

Call the firstFunction function three times.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

3/7

Calling Functions | Start Coder