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:
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