0

For Loop

Hi, I understand how for loops work but when I play with someone and their is a for loop question, I always get it wrong. For example; int arr[] = {5,2,3,7,8} for (int i = 1; i > 10; i++;) { arr [0] += arr [i] } cout << arr [0] << endl; Then it will be what is the output of this code? I know this code is a bit off but I just typed it as quick as i can so you can understand what i am stuck on. Thanks.

3rd Oct 2016, 12:29 AM
ChillzTheCoder
5 odpowiedzi
0
it gives garbage value.. see ur code is wrong.
3rd Oct 2016, 1:32 AM
Shani
Shani - avatar
0
like i said i rushed the code so u could understand what im saying.
3rd Oct 2016, 2:14 AM
ChillzTheCoder
0
yeh thanks. I understand for loops i just get stuck at these questions in the play section.
3rd Oct 2016, 3:01 AM
ChillzTheCoder
0
your code is wrong.. it should be like this. #include <iostream> using namespace std; int main() { int arr[] = {5,2,3,7,8}; int i; for (i = 1; i < 5; i++) { arr [0] += arr [i]; } cout << arr [0] << endl; return 0; }
3rd Oct 2016, 2:20 PM
Iñnøcent'x ShoaIb
Iñnøcent'x ShoaIb - avatar
0
The question has been answered.
4th Oct 2016, 12:16 AM
ChillzTheCoder