Newbie in c++ Some one help me with this.

I am having trouble in pointers

1. Consider the given function;
void set(int *ptr)
{
*ptr = 180;
}

Show how to call the set function so that it set interget variable

Int x;

to 180.


2. Consider the given function;
void change(int & a)
{
a = 10;
}
Show how to call the change function so that it set interget

int x;

to 10;

Last edited on
1
2
set(&x);
change(x);


I've now done your homework for you, but if this is beyond you, you're in big big trouble and you should either give up now or start turning up to class.
what this is trying to show you is that operator & has 2 versions (it actually has 3 or more**): address of and reference. you can find far better written material online about these two than I can write here in short, but that is what you need to review.

** & can also mean bitwise and.
Topic archived. No new replies allowed.