Prepare
Practice
Interview
Aptitude
Reasoning
English
GD
Placement papers
HR
Current affairs
Engineering
MCA
MBA
Online test
Login
Online Practice Test
>
c
« Previous
Next »
What is the output of the following code?
void main()
{
int i=0;
while(i++<10)
{
if(i<5 && i<9)
continue;
printf("\n%d\t",i);
}
}
Options
- 5 6 7 8 9 10
- 1 2 3 4 5 6 7 8 9
- 6 7 8 9 10
- 5 6 7 8 9
CORRECT ANSWER : 5 6 7 8 9 10
Discussion Board
Continue;
Continue; statement after if condition won''t allow to execute printf till if condition gets fail,(continue allow execution of code to jump to while loop again) hence printing 5..10 numbers.
Shailesh Kulal 06-15-2021 10:16 AM
Logical operation comes first before adding 1 to i
i++ < 10
1. The logical operation comes first (e.g. i < 10).
2. Then the +1 in i++ is added upon going inside the while loop.
3. This is why at i = 9 at beginning, it will go inside the while since it is less than 10. Upon going in +1 is added to make it 10 so upon printing it becomes 10. This is why the output will be 5 6 7 8 9 10.
Hope this explanation helps you guys.
centzbanaag 12-14-2016 10:45 PM
fully explain plz
expain...i could not understand.....
Radhe 09-14-2016 12:32 AM
Its all about post increment and pre increment
10 is printed because when condition is i++<10 at that time i was 9 after comparision value of i get increment i.e 10
Mahesh 01-3-2016 12:15 PM
comment
plz explian...the output will be printed from 1to 9 know??
bandaru hariteja 07-12-2015 02:39 AM
why
after while() statement, i will be starting from 1.
when i reaches to 9, while() statement is assessed to be true, and i increments to 10, then 10 will be printed
JackizeZ 03-31-2015 05:39 AM
c
iam not getting clearly how it will print 10?
subbu 03-10-2015 04:43 AM
Reason
For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while and do...while loops, continue statement causes the program control passes to the conditional tests.
Neha 11-11-2014 10:10 AM
How 10 is printed??????
the condition is "i++<10"....... while i=10 the condition false and the loop ll be terminated right??? then how 10 is printed??
Suganya 10-12-2014 12:19 AM
answer to your question
Above code will not give any output as continue again starts the loop uptill i is 4 and then it will skip the if condition
Ami Sheth 08-9-2014 03:49 AM
Post Increment
This Code may help you understand the above logic better !
main()
{
int c;
c = 5;
printf(“%d\n”, c); //5
printf(“%d\n”, c++); //5
printf(“%d\n\n”, c); //6
c = 5;
printf(“%d\n”, c); //5
printf(“%d\n”, ++c); //6
printf(“%d\n”, c); //6
return 0;
}
Sivaprakash G 07-15-2014 11:37 PM
@saranya
Well Saranya I think the answer is write as the 'continue' statement is only execute when i<5 and i<9 that means when i is equal to 5 the 'continue' will no longer be executed and the value of i will be printed till the while is falsed.
TGX 09-20-2013 06:26 AM
explain
its starting from the increment of i++ condition, so how its possible to come like this
saranya 07-30-2013 05:36 AM
« Previous
Next »
Write your comments
*
*
Email must be in the form someone@domain.com
*
*
Enter the code shown above:
Please enter the code shown above
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)
Related Content
C test (42)
C (12)
C++ for beginners (10)
C++ (20)
C++ (24)
C++ (18)
C++ (14)
C++ (12)
C++ (15)
C++ (15)
Data structure (20)
Data structure (10)
Data structure (10)
Data structure (10)
PERL (25)
VC++ (11)
Oops (30)
Mainframe (41)
Mainframe (15)
Embedded systems (15)
OOAD (49)
Advertisement
▲