# Fmod question

• 04-17-2009
Fmod question
Hi guys,

There is one final code question im having trouble with on this mock paper, since you guys helped me learn so much on the last question, i hope you dont mind me asking this one.

This is the code and it asks what will the output be:

Code:

```int i[5] = {1,2,3,4,5}, j = 0; int* k = &i[0]; for ( ; j < 5; k = &i[j++]) { if ( fmod((double)*k,2.0) == 0.0 ) printf("%d",*k); }```
This is my understanding:
Quote:

Declare i as an interger with 5 characters max. The values of the 5 characters are 1,2,3,4 and 5.
Declare j as an interger with value 0.
Set k as a pointer to the memory location of the first character of i (in this case 1).

Then start a for loop, when j is less than 5, then update the memory location i (linking to k) with j + 1.

If this condition is true then run the if command.
Is what I have said correct? In this case, what does the code &i[j++] actually do, increase the char index of i?

Is it correct to say i is all of the values 1,2,3,4,5?

What does the fmod question actually do in the if loop?

Any help you can give to help me understand this would be much appreciated!

James
• 04-17-2009
slingerland3g
fmod fmod - C++ Reference

&i[j++] will 'post increment' the value at jth element of the array i.
• 04-17-2009
Ok ill look into fmod, but to start me off,

If j is equal to 0 and then &i[j++] is run, then that will be the equivalent of i[1] is that correct? Which in my case in 2.

Can you also tell me if i have this right:
Quote:

Declare i as an interger with 5 characters max. The values of the 5 characters are 1,2,3,4 and 5.
Declare j as an interger with value 0.
Set k as a pointer to the memory location of the first character of i (in this case 1).

Then start a for loop, when j is less than 5, then update the memory location i (linking to k) with j + 1.

If this condition is true then run the if command.