Function with Argument Examples in C++


Example Program

Here is the simple program for printing functions with arguments and without arguments examples in C++.

Source Code Example : 1

#include<iostream>
using namespace std;
void add(int,int);
int main()
{
    int a,b;
    cout<<"\nEnter The Two Values:";
    cin>>a>>b;
    add(a,b);
    return 0;
}
void add(int a,int b)
{
    int c;
    c=a+b;
    cout<<"\nAddition:"<<c;
}
To download raw file Click Here

Output

Enter The Two Values:45
67
Addition:112

Source Code Example : 2

#include<iostream>
using namespace std;
void add();//Function Declaration
int main()
{
  add();//Function Calling
  return 0;
}
void add()//Function Definition
{
    int a,b,c;
    cout<<"\nEnter The Two values:";
    cin>>a>>b;
    c=a+b;
    cout<<"Addition:"<<c;
}
To download raw file Click Here

Output

Enter The Two values:56
53
Addition:59

Source Code Example : 3

#include<iostream>
using namespace std;
void myFunction(string fname)
{
    cout<<fname<<"Kumar\n";
}
int main()
{
    myFunction("Arun");
    myFunction("Ram");
    myFunction("Aswin");
    return 0;
}
To download raw file Click Here

Output

ArunKumar
RamKumar
AswinKumar

Source Code Example : 4

#include<iostream>
using namespace std;
int add(int,int);
int main()
{
    int a,b;
    cout<<"\nEnter The Two Values:";
    cin>>a>>b;
    cout<<"\nAddition:"<<add(a,b);
    return 0;
}
int add(int a,int b)
{
    int c;
    c=a+b;
    return c;
}

To download raw file Click Here

Output

Enter The Two Values:56
43
Addition:99

Source Code Example : 5

#include<iostream>
using namespace std;
int add();
int main()
{
    cout<<"\nAddition:"<<add();
    return 0;
}
int add()
{
    int a,b,c;
    cout<<"\nEnter The Two Values:";
    cin>>a>>b;
    c=a+b;
    return c;
}
To download raw file Click Here

Output

Addition:
Enter The Two Values:56
65
121

Basic Programs


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes