Int Array (Basic)

Define an int array variable named arx with 3 slots, and stuff a 7 in the last slot

int arx[2]=7;

Is this correct?
Last edited on
@Dkob1

int arx[2]=7;

Is this correct?


Sorry, but no. Remember, arrays start with zero and end one number below the one you're using.
So, you have only, arx[0] and arx[1]. Two slots. You need to declare it as
1
2
3
int arx[3];
// Then you can use
arx[2] = 7;
Oh I was thinking three slots would be 0, 1, 2.
Ok Thanks.
Did you define this variable as:

int arx[3]; initially?

That means that if you want to access the last index of this array, it would be [2]
Topic archived. No new replies allowed.