C++ Function Arguments Passing: Passing by Value

Introduction

When we pass an argument to a function, a copy of that argument is made and passed to the function if the function parameter type is not a reference.

This means the value of the original argument does not change.

A copy of the argument is made.

Example:

#include <iostream> 

void myfunction(int byvalue) 
{ 
    std::cout << "Argument passed by value: " << byvalue; 
} 

int main() /*from   w  w w .  j  a  va 2 s.c om*/
{ 
    myfunction(123); 
} 

This is known as passing an argument by value or passing an argument by copy.




PreviousNext

Related