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 6 of 15.
Ankit Kumar said:
9 years ago
When x=-1 to x=4 in this case, continue statement executed by increasing value of x only not go to print statement
When x=5 in this case break statement executed and loop will terminated
So zero times print statement executed.
When x=5 in this case break statement executed and loop will terminated
So zero times print statement executed.
(3)
Madhu Chandra said:
1 decade ago
The continue statement under if condition will keep on running the executing for loop by increment 1 and then after 6 iterations the x value becomes 5 by increment 1 and in 7th iteration it will fail, then go break out from loop.
Hemant Sharma said:
1 decade ago
Let's think what's compiler reads this program.
Since when i<5 it skips the remaining part and when i>=5 it breaks the loop and exit the function. As no print command outside the loop so there is 0 times print, that's it.
Since when i<5 it skips the remaining part and when i>=5 it breaks the loop and exit the function. As no print command outside the loop so there is 0 times print, that's it.
K@vy@ said:
1 decade ago
Here when the loop start if x<5 it will continue but it won't print anything otherwise if x>5 it will take else statement and it will break. If it breaks there won't be any printing. So there is no printing of indiabix.
Kvamshavardhanreddy said:
1 decade ago
Giving that if x<5 after that we used continue , it means it performs operation from next line it self after that there is a break statement when compiler performs break it it is out of loop so INDIABIX is not printed.
Laljijosh said:
6 years ago
Ans 0 is True.
Because x= -1
Negative value stored in 2'nd compliment.
(-1 ) 2nd compliment value is definatly x>10.
And for loop condition is x<=10.
Condition False and out of the loop.
So, the Ans is 0.
Because x= -1
Negative value stored in 2'nd compliment.
(-1 ) 2nd compliment value is definatly x>10.
And for loop condition is x<=10.
Condition False and out of the loop.
So, the Ans is 0.
(31)
Nazia firdous said:
1 decade ago
If this program having print statement outside the main then it will print one time.
Otherwise if in else part break will not be there then it will print. We have to write this prog in different way then it will print.
Otherwise if in else part break will not be there then it will print. We have to write this prog in different way then it will print.
Pandu said:
1 decade ago
It prints 0 times because
unit x<5 the 'if' part gets executed,which contains the 'continue' statement and it simply transfers the control to the begining of the loop iteratively for 6 times....
unit x<5 the 'if' part gets executed,which contains the 'continue' statement and it simply transfers the control to the begining of the loop iteratively for 6 times....
Jajanpreet Singh said:
1 decade ago
ITS SIMPLE:
As soon as x reaches value 5.
The block with "break" is executed which cause the compiler to abandon the loop and HENCE ANY OF ITS FURTHER ITERATIONS (EVEN THE STATEMENT AFTER BREAK IN SAME BLOCK).
As soon as x reaches value 5.
The block with "break" is executed which cause the compiler to abandon the loop and HENCE ANY OF ITS FURTHER ITERATIONS (EVEN THE STATEMENT AFTER BREAK IN SAME BLOCK).
Navdeep Charan said:
1 decade ago
What will be the Output of this program and How?
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=10;
while(++a || ++b)
{
printf("%d %d",a,b);
break;
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=10;
while(++a || ++b)
{
printf("%d %d",a,b);
break;
}
getch();
}
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers