function declaration in c++ code example
Example 1: function call in c++
#include <iostream>
using namespace std;
void swaper(int &,int&) ;
int main () {
int a = 100;
int b = 200;
swaper(a, b);
cout << "After swap, value of a :" << a << endl;
cout << "After swap, value of b :" << b << endl;
return 0;
}
void swaper(int &x, int &y)
{
int temp;
temp = x;
x = y;
y = temp;
}
Example 2: 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 3: function in c++
#include <iostream>
using namespace std;
void function(){
cout << "I am a function!" << endl;
}
int main()
{
function();
return 0;
}
Example 4: functions in C++
void Hello() {
std::cout << "Hello";
}
int main () {
Hello();
}
Example 5: function declerations in C++
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <fstream>
using namespace std;
void function_one(double, double, double);
int main() {
double r1 = 1.0;
double r2 = 2.0;
double x = 0.0;
function_one(r1, r2, x);
return 0;
}
void function_one(double rmin, double rmax, double x0) {
cout << "Function got called" << endl;
}
Example 6: function in c++
#include <iostream>
using namespace std;
void myFunction() {
cout << "I just got executed!";
}
int main() {
myFunction();
return 0;
}