# Simple Example Program for Passing pointers to functions In C++

## Pass By Reference Definition

• Each parameter was followed by an ampersand sign (&). (&) will pass an address of the original variable instead of by value.
• In Passed by reference, the original variable and the function variable use the same memory/variable for the parameter. If the function variable modifies the parameter value, the effect is visible to the original variable.

## Syntax

``````//Function - Pass By Reference
void fn_name(int *var1,int *var2)
{
// Code
}

//Main Code- Pass By Reference
fn_name(&orginal_var1,&orginal_var2);``````

## Simple Example Program for Passing pointers to functions

``````/*##Simple Example Program for Passing pointers to functions In C++*/
/*##Simple Add Numbers C++ Programs,pointers Example C++ Programming*/
/*##Pass By Reference Function C++ Example Program In C++ Programming*/

#include <iostream>
#include<conio.h>

using namespace std;

// Declare Add Numbers Function Using Pointer

void add_numbers(int *value1, int *value2, int *result) {
*result = *value1 + *value2;
}

int main() {
// Declare Variables
int number1, number2, result = 0;

cout << "Pointer Example C++ Program : Passing pointers to functions In C++ \n";

cout << "Enter value of Number # 1: ";
cin>>number1;
cout << "Enter value of Number # 2: ";
cin>>number2;

//Print Values Pass to Reference
cout << "Before Pass to Reference :  Number # 1=" << number1 << ",  Number # 2=" << number2 << ", Result # :" << result << " \n";

//Call add_numbers Function By Passing Reference

//Print Values Pass to Reference
cout << "After  Pass to Reference :  Number # 1=" << number1 << ",  Number # 2=" << number2 << ", Result # :" << result << "\n";

getch();
return 0;
}``````

## Sample Output

``````Pointer Example C++ Program : Passing pointers to functions In C++
Enter value of Number # 1: 100
Enter value of Number # 2: 200
Before Pass to Reference :  Number # 1=100,  Number # 2=200, Result # :0
After  Pass to Reference :  Number # 1=100,  Number # 2=200, Result # :300``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.58260494,"math_prob":0.8753731,"size":4728,"snap":"2023-40-2023-50","text_gpt3_token_len":1043,"char_repetition_ratio":0.29339543,"word_repetition_ratio":0.30268198,"special_character_ratio":0.25994077,"punctuation_ratio":0.071428575,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99569684,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-10-02T04:56:11Z\",\"WARC-Record-ID\":\"<urn:uuid:7a45ff89-6585-4777-91a3-0f6198b3b17b>\",\"Content-Length\":\"47213\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7d1e0c21-6746-49fc-81f8-7f3a064c7bd1>\",\"WARC-Concurrent-To\":\"<urn:uuid:c41a9f0e-c9df-455c-84c4-a5cdf79b6874>\",\"WARC-IP-Address\":\"172.253.63.121\",\"WARC-Target-URI\":\"https://www.cpp.thiyagaraaj.com/c-programs/c-pointer-example-programs/simple-example-program-for-passing-pointers-to-functions-in-c\",\"WARC-Payload-Digest\":\"sha1:L6SF2VKW4SO7L5GAC26WFEZ6J3NAMX6Q\",\"WARC-Block-Digest\":\"sha1:CWA6ZIBNSLOXBWKIGYT4DENFVYAKMH2N\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510967.73_warc_CC-MAIN-20231002033129-20231002063129-00851.warc.gz\"}"}