Lesson 7

Functions

Functions help organize your programs into smaller reusable parts. They make code easier to read, maintain, and test.

Simple Function

Example
#include <iostream>
using namespace std;

void greet()
{
    cout << "Welcome to C++ programming." << endl;
}

int main()
{
    greet();
    return 0;
}

Function with Return Value

Example
#include <iostream>
using namespace std;

int add(int a, int b)
{
    return a + b;
}

int main()
{
    cout << "Sum = " << add(5, 3) << endl;
    return 0;
}
Book Tip:

This short lesson is part of a larger learning path. The full book expands each topic with more explanation, exercises, and projects.