+ 4

How to loop through an array and print its elements in C++?

I have a problem... How to make this code work? #include <iostream> using namespace std; int main() { int arr[3] = {0,1,0}; .......} And then what to write after that? //Thanks

27th Oct 2017, 6:44 PM
DeltaTick
DeltaTick - avatar
3 Answers
+ 3
int arr[3] = {0,1,0}; for(int i = 0; i < 3; i++) { cout << arr[i]; } You're kidding about this or what :)
27th Oct 2017, 7:45 PM
Ipang
+ 2
Ipang, do you also know how to loop through 2d arrays?
29th Oct 2017, 2:03 AM
DeltaTick
DeltaTick - avatar
+ 1
@Reuben I'm learning about that too, here's what I did just minutes ago, there's a weird thing though, there's a line that doesn't get executed in the end before return, idk why or what. Maybe you can check if that line works?? https://code.sololearn.com/csYNBi1m9jVx/?ref=app
29th Oct 2017, 4:19 AM
Ipang