C Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - General Questions (Q.No. 1)
1.
How many times "IndiaBIX" is get printed?
#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf("IndiaBIX");
}
return 0;
}
Discussion:
142 comments Page 5 of 15.
Yogesh Sharma said:
1 decade ago
The printf Code Line is unreachable in the function
As The control from the if Statement is revert back to For loop increment till x<5 and as it become greater than 5 it stop executing the program.
That is in any circumstances the Printf Code is not executing.
Hence Option C is correct
As The control from the if Statement is revert back to For loop increment till x<5 and as it become greater than 5 it stop executing the program.
That is in any circumstances the Printf Code is not executing.
Hence Option C is correct
Utsav said:
1 decade ago
#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
printf("\nIndiaBIX");
else
break;
printf("\nIndiaBIX");
}
return 0;
}
Indiabix is printed 12 times. why ?
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
printf("\nIndiaBIX");
else
break;
printf("\nIndiaBIX");
}
return 0;
}
Indiabix is printed 12 times. why ?
Vishnu o.m said:
1 decade ago
Indiabix is not printed because the continue instruction will take the control back to the for loop until i<5, till then printf don't get executed. When if statement fails, else statement break is executed which will take the control out of the loop. Hence printf is not executed.
Pooja said:
1 decade ago
Up to the x<5 condition the else statement is executed. But when x=5 then else statement is executed, but in else statement break statement is there.
Because of this execution is stop and loop is terminated. And printf function is not executed.
Thus "IndiaBix" will not print.
Because of this execution is stop and loop is terminated. And printf function is not executed.
Thus "IndiaBix" will not print.
Vipin dhawan said:
1 decade ago
In above statement first (b++) the value remains 5,
Second (++b) the value gets increase by one so now value is 6, third (++b) the value gets increase by one so now value is 7, fourth (++b) the value gets increase by one so now value is 8.
But the answer is come 26.
Second (++b) the value gets increase by one so now value is 6, third (++b) the value gets increase by one so now value is 7, fourth (++b) the value gets increase by one so now value is 8.
But the answer is come 26.
SANDEEP KUMAR SINGH said:
1 decade ago
The first condition is x<5, that's why loop will continue and keep incrementing value of x until x=5.
When x=5 then condition will go to else part and since break statement is there it will come out of loop.
So, it is not going to print "IndiaBIX".
When x=5 then condition will go to else part and since break statement is there it will come out of loop.
So, it is not going to print "IndiaBIX".
Basant kumar soni said:
1 decade ago
When the loop is start from -1 to 10 ,firstly check the if condition and follow the continue statement and from -1 to 5 condition is satisfied ,then 6 condition is satisfied and else statement go to break and terminate the loop
so that nothing will be print
so that nothing will be print
P.vijayan said:
1 decade ago
continue: go back the control to starting of the loop
break: terminate the execution of the loop
if(i<5) that the values are (-1,1,2,3,4) then control back to loop
else tat is i=5 then terminate the execution
So nothing to be printed.
break: terminate the execution of the loop
if(i<5) that the values are (-1,1,2,3,4) then control back to loop
else tat is i=5 then terminate the execution
So nothing to be printed.
Sri Harsha said:
9 years ago
Continue statement in the loop will not allow to print.
Because when the continue statement encountered by the c compiler it simple goes to the beginning of the loop.
The x gets incremented up to 5 and after that loop will be braked.
Because when the continue statement encountered by the c compiler it simple goes to the beginning of the loop.
The x gets incremented up to 5 and after that loop will be braked.
(1)
ANJUM said:
1 decade ago
There is no {} for if or else, so the statement next to if is continue which starts the next iteration when if condition becomes false control moves to else then to break which takes the control out of loop and program terminates.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers