C++ Examples

C++ program to write a program to add two numbers using call by value.

  1. Write a C++ Program to print a welcome text in a separate line.
#include <iostream>
using namespace std;

   //Function defination for addition of two numbers

int add(int x, int y)
{
    int z = x + y;
    
    return z;
}

int main()
{
    int a,b,c;
    
    cout<<"Enter first number to add: ";
    cin>>a;
    cout<<"Enter second number to add: ";
    cin>>b;
    
    //Calling add function for addition of two numbers
    
    c = add(a,b);
    
    cout<<"Addition of two numbers using call by value is "<<c;

    return 0;
}

Output

Enter first number to add: 5
Enter second number to add: 4
Addition of two numbers using call by value is 9
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments