What is the difference between pass by reference and pass by
value?

Answer Posted / chinna

in Pass by value; if any change in variable in the sub-
function may not reflected to the main function. where as
in pass by reference the change in the variable may reflect
to the original value in the main funtion.

ex : // Pass by Reference

void Get( int &nIndex){
nIndex = 10;
}

void main()
{
int x = 100;
cout<<Get( x );
}

o/p : 10;

ex : // Pass by Value

void Get( int nIndex){
nIndex = 10;
}

void main()
{
int x = 999;
cout<<Get( x );
}

o/p : 999

Is This Answer Correct ?    29 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

1637


write a program that takes input in digits and display the result in words from 1 to 1000

1985


What is destructor example?

593


Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?

4235


What is destructor give example?

601






What is difference between oop and pop?

611


What is protected in oop?

602


How do you define a class in oop?

626


What is pure oop?

597


What is polymorphism in oops?

556


What is the main purpose of inheritance law?

667


Write a program to reverse a string using recursive function?

1788


What is a class oop?

592


Can static class have constructor?

582


Can bst contain duplicates?

664