Write a C++ program which define function with no argument and return value.

Here we are considering add() function as user defined function which further takes no argument and have an integer value as return type.

Program Code:
#include <iostream>
using namespace std;


// user defined function with return value (int) and have no argument are passed in it from main()

int add() 
int c, a, b;
cout<<"Enter the value of first number :" ;
cin>>a;
cout<<endl;
cout<<"Enter the value of second number :" ;
cin>>b;

cout<<endl;
c = a + b;
return c;

// main() function with user defined function call

int main() 
int x; 

// user defined function call in the main() with no argument passed in it

x = add(); 
cout<<"Addition of two given number is : ";
cout<<x;
return 0;
}

The program output is tested on www.jdoodle.com
Output:

Enter number a : 2
Enter number b : 3
Addition of a and b : 5


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: