+ 3
What is the meaning of this "for" line? What output should i expect?
#include<iostream> Using namespace std; int main() { int arr[5] = {10, 0, 20, 0, 30}; For(int i : arr) { cout<< arr[i] <<"\n"; } }
2 Respostas
+ 4
Using : in a for loop just goes through all the items in the array. But since the items are there, it will output garbage values. To get the items correctly, use:
for(int i : arr) {
cout << i << endl;
}
Just a small note: For should be for and Using should be using.
+ 2
Ha... Thanks.. and for the note I typed in my phone!! Autocorrect dictionary! :D