Array question?

int foo (void)
{
int i, j, k;
int grid[4];

for (i = 0; i < 4; i++)
{
grid[i] = 2;
for (j = 1; j < = 3; j++)
grid[j] = grid[i]+ 3;
}
return (grid[1]);
}
foo returns : ?

Still can not figure out what this function returns... It is unlike other array problems I have done... I mean Grid[i]=2 every time it loops? WHat? Can someone explain line by line or point in the right direction? Thanks.
I mean Grid[i]=2 every time it loops? WHat?

Yeah, that's what it does. No one says these examples/exercises have to make any sense.
Ok well if grid I always equals two doesnt that make grid j always 5 (3+2)? Also Return grid [1]. What does that mean? does it mean run it when I J and K each have 1 plugged in for them? Still not sure what I should be returning. Thanks.
Ok well if grid I always equals two doesnt that make grid j always 5 (3+2)?

Yes, it does.
return grid[1]; returns the array element at index 1.
which would still be 5 right? So grid[1] returns 5?
Yes.
foo returns 5 is my answer then! Thanks my friend!
Topic archived. No new replies allowed.