Click here to Skip to main content
15,914,447 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
I meant to ask in both of the functions below, parameters are getting the values by reference or what? What's the difference between the two?
int main()
{
int a,b;
Stack stack_numbers
cin>>a>>b;
call (&a,&b);
do_command(stored_numbers);
}

Function 1
call(int *a1,int *b1)
{
//whatever
}

Function 2
bool do_command(Stack &numbers)
{
//whatver
}
Posted

Go through the links :

http://www.oocities.com/sstutor/pointer2a.htm[^]

http://www.geekinterview.com/question_details/14458[^]

I am sure after this you can answer the questions yourself!
 
Share this answer
 
Comments
optimus_prime1 24-Dec-10 1:25am    
Ok, I get this
One is C style pass I was using and the other is C++ style pass by refernce.
Thanks for the nice link. Its really cluttered sometimes on the web. :)
Tarun.K.S 24-Dec-10 1:31am    
You are welcome!
Do you know the concept of Call by value and call by reference ??
Please search google...
 
Share this answer
 
Avoid pointer use in function prototypes when possible, renders compilers unable to make many optimizations. Prefer to use reference, so you at least do not need to check against null pointer. The cases where you would pass in a pointer might relate to the use of void * or inheritance.

Pass by reference or const reference should be preferred for classes for efficiency, but pass by value is acceptable for fundamental types since they are more likely to go into registers.

Note that pass by value makes a copy of the structure, that's why it is highly inefficient except for fundamental types.
 
Share this answer
 
v2
Comments
optimus_prime1 24-Dec-10 1:12am    
So, basically both of my above functions were call by reference? Although pointers use should be avoided?
Tarun.K.S 24-Dec-10 1:22am    
No. Function1 is call by value and Fucntion2 is call by reference.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900