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

May 30, 2021 at 7:35pm
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 May 30, 2021 at 7:40pm
May 30, 2021 at 7:48pm
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.
May 30, 2021 at 11:30pm
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.
May 31, 2021 at 1:27am
Topic archived. No new replies allowed.