# Help with Arrays 1

/Can someone please explain what is happening in this code? What is the outcome and why? I need step by step on this please. I am having a hard time understanding arrays!/

#include <stdio.h>
int main(void) {
int i, t;

``````    t = 0;
for(i = 1; i < 5; i++)
t[i] = t[i - 1] + i;
printf("%d",t);
return 0;
``````

}

its simply calculating sum of first 4 numbers.
t=t+1=1; t=t+2=1+2=3; t=t+3=1+2+3=6;
t=t+4=1+2+3+4=10;

Hey pro,

You see the steps here first you initialized an integer array of 5 elements then in the next step you had given its first element an value of 0 then your loop runs for 4 times and has you had not mentioned any brackets in for loop sor the only statement after it is get executed it the loop and the statement t[i] = t[i-1] + i is finding the sum ie t = t+1 = 0+1 =1,t=t+2=1+2=3,t=t+2=3+2=5,t=t+4=5+4=9.
and so finally the output is 9, hope i am right and you find it ok, but if there is any mistake that you might think then please comment it to me.

Happy coding

What does this mean: t[i] = t[i - 1] + i;

What is this for loop saying? for(i = 1; i < 5; i++)