codegurukool.com · Free coding tutorials & online compiler

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;
}

Run this code in the online editor

← C++ memory managementC++ function overloading →