Thread: Fmod question

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    93

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

  2. #2
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    fmod fmod - C++ Reference

    &i[j++] will 'post increment' the value at jth element of the array i.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    93
    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:
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM