Prototyping
The following is the complete C++ source code for a simple console application that demonstrates prototyping.
You either have to define your custom routines above main() so that they can be used within main() or prototype them. C++ allows you to prototype custom routines so that you can put their implementation below main.
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
//
//Prototypes
//
void sayHello(string pName);
int add(int p1, int p2);
//
//Main.
//
void main()
{
sayHello("Mike");
cout << "2+2=" << add(2,2) << "\n";
}
//
//Implementation section.
//
void sayHello(string pName) {
cout << "Hello " + pName + "\n";
}
int add(int p1, int p2) {
int result;
result = p1 + p2;
return result;
}