Showing posts with label pass by value. Show all posts
Showing posts with label pass by value. Show all posts

20130411

How to distinguish between call by value, call by reference, call by address

/*How to distinguish between call by value, call by reference, call by address.
Program to distinguish between pass by value,pass by reference,pass by address. Call by reference and call by address affects the calling value while call by value doe not. Most important difference is that in call by value new object is created which is some times such as when size of the variable is too large is not desirable so call by reference is preferred over call by value*/

#include<stdio.h>
#include<iostream>
using namespace std;
void callbyreference(int * x);//pass by address
int main()
{
int x;
x=10;
printf("Before x=%d",x);//10
callbyvalue(&x);
printf("\nAfter x=%d",x);//15
printf("\n");
return 0;
}

void callbyreference(int * x)
{
*x=*x+5;//mind the*
}


//CALL BY REFERNCE, PASS BY REFERNCE
/*