Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Simple Function Creation | Introduction
C++ Functions

book
Simple Function Creation

Task

Swipe to start coding

Your task is to create a function and call this function in the main() function:

  • Create function signature:
    • specify std::string return type;
    • specify helloWorld as the name of the function
  • Return string "Hello World".
  • Call the function using its name.

Solution

cpp

solution

#include <iostream>

std::string helloWorld()
{
return "Hello World!";
}

int main()
{
std::cout << helloWorld();
}

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 3
#include <iostream>

___ ___()
{
___ "Hello World!";
}

int main()
{
std::cout << ___();
}
toggle bottom row
some-alt