1. ## Exam question help

Ok so I got this question in one of our exams and I havn't a clue on how to answer it. Can someone please explain what the question is asking?
Thanks

b) If a program contains the main function
Code:
```void main()
{  int X=2, Y=11;
func(X,&Y);
printf("%d %d\n",X,Y);
}```
and another function
Code:
```void func(int P, int *Q)
{ int X;
X=(*Q);
P=X/3;
(*Q)=P+1;
}```
what two values will the main function print out?

2. The question is asking what the output would be if you ran this program. It is mostly a basic arithmetic question.

3. have a read through it and work out what each line is doing to break it down into easier to understand points.
you may find you are over-complicating it, read the question and the functions carefully.

4. Hint, all of this:

Code:
```              X=(*Q);
P=X/3;
(*Q)=P+1;```
is just meant to confuse you.

5. Ok thanks, but I'm still not really understanding how the first function has anything to do with the second. C does not click with me.
Is it saying Q is pointing to x from the first function?
Does X = 5/3?
And what does the
Code:
`func(X,&Y);`
mean?

6. pointers are very important and if you don't fully understand them then now is the best time to sit down and make sure you do.
have a look at;
Cprogramming.com Tutorial: Pointers
this explains about pointers and how they operate, after that see if it gives you any more insight.
if that doesn't help then just shout for help and im sure someone will try to expand on it.
use it to refer to your example from the question to see how it relates to it

7. Originally Posted by Terrak
pointers are very important and if you don't fully understand them then now is the best time to sit down and make sure you do.
have a look at;
Cprogramming.com Tutorial: Pointers
this explains about pointers and how they operate, after that see if it gives you any more insight.
if that doesn't help then just shout for help and im sure someone will try to expand on it.
use it to refer to your example from the question to see how it relates to it
Yeah I'm gonna give that tutorial another look over.

8. So, anyone got an answer for me?

9. Work through it on paper. What part is confusing to you?

Quzah.

10. Oh oh. I know. I know.

11. Originally Posted by quzah
Work through it on paper. What part is confusing to you?

Quzah.
Mainly the func(....) part. I just don't understand what it does.

12. Originally Posted by ÉireKarl
Mainly the func(....) part. I just don't understand what it does.
Well gosh, that is like saying reality confuses Quzah. We don't know exactly which part gives him the problem(s).

13. Originally Posted by Overworked_PhD
Well gosh, that is like saying reality confuses Quzah. We don't know exactly which part gives him the problem(s).
Fine then you want me to code it ?

Code:
`func(X,&Y);`

14. You know that P and Q are just copies of X and Y, right?

so in func(), why don't you print up the values of P and Q and X and whatever else interests you.

See what these variables are all doing.

You know that since *Q is the address of Y, that whatever you do to it, will be affecting Y, but that's not true with X since the func() is not getting the address for it.

If a function is to change the value of a variable, it has to know the address of that variable.

You see that in simple things like scanf("%d", &number). Since scanf() is going to change the value of number, you have to give it the address of number.

But: printf("%d", number) - no address needed, since printf() is not going to change the value of the variable number.

You know that P and Q are just copies of X and Y, right?

so in func(), why don't you print up the values of P and Q and X and whatever else interests you.

See what these variables are all doing.

You know that since *Q is the address of Y, that whatever you do to it, will be affecting Y, but that's not true with X since the func() is not getting the address for it.

If a function is to change the value of a variable, it has to know the address of that variable.

You see that in simple things like scanf("%d", &number). Since scanf() is going to change the value of number, you have to give it the address of number.

But: printf("%d", number) - no address needed, since printf() is not going to change the value of the variable number.
Ahh, ok thanks for narrowing that down!

So... does X=11 and Y=14/3 d(*.*)b?