Question
C Programming Can someone please explain me while the following (c) code prints out 6? for (i=1; x i=5, true, loop prints 5 ---> i=6,
C Programming
Can someone please explain me while the following (c) code prints out 6?
for (i=1; x<=5; i++);
printf ("%d",i);
i=1 initializes the the loop, it is being tested whether it is <= 5 or not. This statement is true, so it goes into the loop and prints 1.
After that, i++, means 1+1=2, i=2. This statement is being tested and it is true, we go into the loop and print 2.
Then i=3, true, loop prints 3 --> i=4, true, loop prints 4 --> i=5, true, loop prints 5 ---> i=6, false, no loop, don't print 6??!!
I have tried and changed the testing condition into i==0, and it still prints 1. Why would it do that? The Expression i=1 is not true?
Thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started