Call by reference, C/C++ Programming

Call by reference:

Arguments to a function can be passed in two way; one by call by value and other by call

by reference.  Call by value is passed either through a constant or variable.  The call by reference is passed through address operator (&).  In C the function definition argument must be declared as pointer variable to pass by reference, where as in C++ the call by reference can be used without declaring the function arguments as pointer variables.  But in C++ both pointer argument method and without pointer argument can be adopted.

 

void f_ref(int &a, int &b); // void f_ref(int, int) is wrong for reference variable;

void main( )

{int a, b;

f_ref(a, b); // The value a is 10 and b is 20.

 

 

}

void f_ref(int &x, int &y)

{x =10;

y=20;

}

Posted Date: 9/20/2012 7:45:33 AM | Location : United States







Related Discussions:- Call by reference, Assignment Help, Ask Question on Call by reference, Get Answer, Expert's Help, Call by reference Discussions

Write discussion on Call by reference
Your posts are moderated
Related Questions
A palindrome is a string that reads the same from the both the ends. Given a string S convert it to a palindrome by doing character replacement. Your takes is to convert S to palin

C Program for MAXIMUM NO, MINIMUM NO AND SORTING   void main() {           int i,j,t;           int a[5];           clrscr();           for(i=0;i

how to make the coding

Problem: a) Give and Illustrate with the help of diagrams, four topologies for the Network Information System (NIS). b) Give methods for creating user accounts and groups.

how many bytes required to char

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Syntax rules for writing constructor functions Its name must be similar as that of the class to which it belongs. It is declared with no return type (not even void). Ho

Damjibhai and Shamjibhai are two jeweler friends. They decide to play a simple game. The game comprises of removing the jewels for polishing, turn by turn. Once a jewel is removed

Program to design list in c: Write a program in c to insert the values in list void main() { int i=0; char a[20]; clrscr(); printf("Enter the line\n");

Program of swapping two varibales: void swap(int *, int *);   // This is swap's prototype int main() {                 int x = 5, y = 7;                 swap(&x, &