Don't laugh, only been doing C++ for a few days now, just started arrrays on my book and got a little confused as to how this code works out how it does:
#include <iostream>
using namespace std;
int main()
{
int t,i, nums[3][4];
for(t=0; t < 3; ++t) {
for(i=0; i < 4; ++i) {
nums[t]=(t*4)+i+1;
cout << nums[t] << ' ';
}
cout << '\n';
}
system("pause");
return 0;
}
The outcome is:
1 2 3 4
5 6 7 8
9 10 11 12.
Whilst i understand the outcomes themselves, e,g when [t] = 0, and = 0, the result is 1.
In my mind i don't understand how all the possibilities are displayed in the order they are. Because the first time the loop is ran, [t] and are set to 0, so the result is 1. Next loop, surely [t] would be 1 and would be 1, so the result is 6, then next loop [t] = 2 and = 2, the result is 11.
So surely the outcome would be displayed as:
1, 6, 11 ? not 1, 2, 3.
Sorry if you don't understand what i'm going on about But it's confusing me
#include <iostream>
using namespace std;
int main()
{
int t,i, nums[3][4];
for(t=0; t < 3; ++t) {
for(i=0; i < 4; ++i) {
nums[t]=(t*4)+i+1;
cout << nums[t] << ' ';
}
cout << '\n';
}
system("pause");
return 0;
}
The outcome is:
1 2 3 4
5 6 7 8
9 10 11 12.
Whilst i understand the outcomes themselves, e,g when [t] = 0, and = 0, the result is 1.
In my mind i don't understand how all the possibilities are displayed in the order they are. Because the first time the loop is ran, [t] and are set to 0, so the result is 1. Next loop, surely [t] would be 1 and would be 1, so the result is 6, then next loop [t] = 2 and = 2, the result is 11.
So surely the outcome would be displayed as:
1, 6, 11 ? not 1, 2, 3.
Sorry if you don't understand what i'm going on about But it's confusing me