C For loops, help tracing through code
Go to solution
Solved by andrew_on_tech,
Program executes in this order.
- So the program enters the Main method.
- Allocates a int and points it "i"
- Allocates an array of INTs at size 10 with garbled data(for the most part, since your not initializing it)
- Program steps into for loop 1
for (i = 0; i < 10; i++)
array[i] = i;
- The Loop will run 10 times assigning ints 0-9 into array index 0-9 respectively.
- After "i" is no longer less than 10 the loop will exit and the program will enter the second loop
for (i = 0; i < 10; i++)
printf("%d\n", array[i]);
- The Loop will run 10 times printing out the value stored at array index "i"
-
Output will be:
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- Then "i" will no longer be less than 10 so it will exit the loop, hit your return and you will finish your method.
Hopefully this is what you were looking for.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now