creating function in c++ code example
Example 1: how to declare a function in c++
#include <iostream>
using namespace std;
int addition (int a, int b)
{
int r;
r=a+b;
return r;
}
Example 2: functions in C++
void Hello() {
std::cout << "Hello";
}
int main () {
Hello();
}
Example 3: how to make a function in cpp
int max(int num1, int num2) {
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
Example 4: function in c++
#include <iostream>
using namespace std;
void myFunction() {
cout << "I just got executed!";
}
int main() {
myFunction();
return 0;
}