Thread: contents of array

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    12

    contents of array

    Hello all, I am a struggling C++ student and I am stuck trying to figure out the contents of the array "sample" after the following code is executed:

    give declarations:

    int sample[8];
    int i;
    int k;

    What are the contents of "sample" after the following code segment is executed:

    for (k=0; k<8; k++)
    if (k % 2 == 0)
    sample[k] = k;
    else
    sample[k] = k+100;

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Why not compile and run it to see?

    [edit]
    oh heck, look, here you go:
    Code:
    sample[0] = 0
    sample[1] = 101
    sample[2] = 2
    sample[3] = 103
    sample[4] = 4
    sample[5] = 105
    sample[6] = 6
    sample[7] = 107
    Last edited by Hammer; 09-13-2002 at 06:13 PM.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    12
    Thanks for your help Hammer.

    Actually I did try and run it through my compiler. Sorry about the tags, I read the instructions, but forgot to add them.

    Thanks again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Getting the contents of edit boxes into an array
    By earth_angel in forum Windows Programming
    Replies: 3
    Last Post: 07-05-2005, 12:17 PM
  3. Using the debugger to see array contents
    By JohnnyCat in forum C++ Programming
    Replies: 2
    Last Post: 06-23-2005, 02:17 AM
  4. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  5. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM