Passing Memory by reference to different functions

Hey Guys I am new to programming but from what I have done so far I really like it.

I had a question about memory that you pass by reference.... more or less how to use it properly, I get confused on how to set things up and where to indicate that it is sharing a memory location...

example:

# include <stuff>

void example_function(int &variable);

int main()
{
int junk1 = 4 ;

example_function(junk1);
}


void example_function(&variable)
{
cout << variable;
}


what I am wondering is if I am setting up the name for the memory correct, I get confused with the idea of where I put the & and what information I have to put in the function parameters.


if you could give any feedback I would greatly appreciate it... .thanks
void example_function(int &variable)
{
cout << variable;
}

void main()
{
int junk1 = 4 ;
example_function(junk1);
}
Don't worry as you do more C/C++ programming you will be able to figure out the usage of * & in parameters later. They can be confusing for first timers but with experience it all flows. But if you are from Java world, those * & for parameter is indeed a pain in the a*se :P
Topic archived. No new replies allowed.