So I am quite new to C++. It does take time before things stick to my brain and it is not easy to grasp its logic.
I have an issue understanding how code works exactly and how it ends up being this and that result. I use an iOS app called Learn C++ and I do their trivias/quizes, while I may be answering correctly at times, I sometimes also do it without seeing how it ends up being that way (luck or a guess)...
Can someone please explain to me how the output of this becomes 26? I feel really dumb I do but, I don't piece it together, I'd say 21 LOL. Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include "stdafx.h"
#include <iostream>
usingnamespace std;
int main()
{
int a[4] = { 7,9,3,4 };
for (int i = 1; i < 4;i++) // init,condition;increment ; i contains 1 from the first loop right?
{ //statement
a[0] += a[i] + 1; // so.. [0] (which is 7, first in array index?) = [0] + [i] + 1
}
cout << a[0]; // output result to screen (26 -- how is it 26?)
system("pause"); // i know i shouldn't use this but since i'm just learning
}