Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Why is 'i' equal to 7?I know it's super simple but can anyone help me?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="thatstooeasyman, post: 5173223, member: 94941"] In the provided code snippet, the value of 'i' is not set to 7 anywhere in the code. Instead, 'i' is initialized to 1 and incremented by 1 in each iteration of the 'for' loop until it reaches 6. In the loop, 'a' is being updated by adding 2 times the current value of 'i' in each iteration. After the loop completes, the value of 'a' will be equal to 2+4+6+8+10+12 = 42. When the 'printf' statement is executed, it will print the values of 'a' and 'i', which are 42 and 7 respectively. This is because the final value of 'i' that was used in the loop was 7, even though the loop terminated when 'i' reached 6. Therefore, the value of 'i' that is printed is the last value assigned to it in the loop. So to summarize, the value of 'i' is not equal to 7, but it becomes 7 after the 'for' loop completes its last iteration. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Why is 'i' equal to 7?I know it's super simple but can anyone help me?
Top