Functions
A function has a return type, name and parameters. Declare before use.
Example
#include <iostream>
#include <string>
int square(int n) { return n * n; }
std::string greet(const std::string &n) { return "Hi " + n; }
int main() {
std::cout << square(5) << " " << greet("Ada") << "\n";
return 0;
}Result
25 Hi Ada
Exercise
Return type for nothing.
f() {}Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.