Basics of Array need help !!!

Write a statement that assigns to x the value of the next to last element of the array.

1 #define ARR_SIZE 30
2 main() {
3 int x, arr[ARR_SIZE];
4
5
6 return 0;
7 }
Okay. So, The array is 30 big. It holds 30 elements. But, they are not placed between 1-30, they are placed between 0-29. So if you want the first array, you would do arr[0];

If you want the last element of the array, you would do arr[29];

So if you want the value of the next to last element of the array you would do arr[?] Post the answer under me if you get it :)

Then, just do x = arr[?];

Now its done.
The Council agrees that:
⇒ You almost certainly should be using: -
⇒ You almost certainly should be using: ARR_SIZE
⇒ You need to use ARR_SIZE to access the right array element.

Well sir it says that I must use the ARR_SIZE.
I tried: x= arr[28];
Last edited on
hmm Im not sure if I get this 100%. But I guess you could do

x = arr[ARR_SIZE] - 1;
yes, it worked but it must be x =arr[ARR_SIZE]-2; to next to the last number. Thank you sir.
Topic archived. No new replies allowed.