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
How do you declare an integer variable? Explain with an example.

Write a ‘C’ program to accept any 3 digit integer number from the keyboard and display the word equivalent representation of the given number.


#question. write a program number to alphabet in c++..

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci


Q: When should you employ multiple inheritance? A:There  are  three  acceptable  answers:-  "Rarely," "Never," and  "while  the  problem  domain cannot be modeled accurately any

Molecular dynamics for a Lennard-Jones system (in C++) 1. Write a function which reads in the input variables of a molecular dynamics simulation of a Lennard-Jones system. The inpu

Assignment:  write a C program and a MASM procedure.  The C program calls the MASM procedure to perform letter case conversion. Text sections covered:  12.1 to 12.3.1 Write a

What is conversion constructor? explain it .