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
THEORY OF A COMPUTER PROGRAMMING

how to make a game

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

- Create a program that uses at least two functions that will be called from your main. This program is a number game program that asks for parts of your phone and after manipulati

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

I''m trying to write a function that prints the substring if it is found in the string, and after it prints it deletes it from the string so i could print the next substring if it

Question: (a) Describe what are dynamic pointers. Show their memory representations diagrammatically. (b) Write short notes about pointers in arrays, paying attention on

Returning References from Functions Just as in passing the parameters by reference, returning a reference also doesn't return back a copy of the variable , instead an alias is

Ask question #Minimum 100 words acceptedEducational Objectives: After completing this assignment, the student should be able to accomplish the following: Apply generic algorithms i

Define a function in c program: int f1() { static int x=10; return x; } int f2() { int y=5; return y; } extern int z; void f()     {