-
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;
-
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
-
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!