0
Q&A Question about arrays.
What is the output of this code? int arr[ ] = new int[3]; for (int i = 0; i < 3; i++) { arr[i] = i; } int res = arr[0] + arr[2]; System.out.println(res); Can someone explain why this results in 2?
1 Answer
+ 1
For the entire array,
arr[i] = i;
The array content/value is the index of the array, i.e. arr[0] is 0, arr[1] is 1, and so arr[0] + arr[2] is 2.
Hot today
Please help, any idea?
2 Votes
Loop question, I've tried everything that I knew I just don't know. Please help me solve it out
1 Votes
What is wrong? Error on test.
1 Votes
Help me solve this (using loop)
1 Votes
Help me wiht python
1 Votes
how can i flip any word with c++
0 Votes