Home › C++ Tutorial › C++ functions and parameters
C++ functions and parameters
Reusable blocks.
Define a return type and parameters. Default values and references work as parameters. Use void when nothing is returned.
Example code
#include <iostream>
using namespace std;
int add(int a, int b = 10) { return a + b; }
void inc(int &n) { n++; }
int main() {
int x = 1; inc(x);
cout << add(2, 3) << " " << add(2) << " " << x << endl;
return 0;
}