Example 1: C++ program for addition of numbers using a function
kw.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
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out 15 kodingwindow@kw:~$
Example 2: C++ program for addition of numbers using a function
kw.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
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out 15 kodingwindow@kw:~$
Comments and Reactions
What Next?
C++ program for call by value and call by reference
C++ program to add the members of two different classes using the friend function
C++ program to demonstrate the use of math library functions
Advertisement