Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

Identify and control your anxieties

Answered: 1 week ago

Question

Understanding and Addressing Anxiety

Answered: 1 week ago