Example 1: C++ program for addition of numbers using a function
codeaft.cpp
#include <iostream> using namespace std; int add(int a = 7, int b = 8) { return a + b; } int main() { cout<<add()<<"\n"; return 0; }
Output
codeaft@codeaft:~$ g++ codeaft.cpp
codeaft@codeaft:~$ ./a.out 15 codeaft@codeaft:~$
Example 2: C++ program for addition of numbers using a function
codeaft.cpp
#include <iostream> using namespace std; int add(int a, int b) { return a + b; } int main() { int i = 7, j = 8; cout<<add(i, j)<<"\n"; return 0; }
Output
codeaft@codeaft:~$ g++ codeaft.cpp
codeaft@codeaft:~$ ./a.out 15 codeaft@codeaft:~$
Comments and Reactions