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 7 of 15.
Ashish said:
9 years ago
Once the value of x reaches 5 it executes else part, which is break statement, break statement terminates loop. This means the control will never encounter printf statement. Hence no 'IndiaBix' will be printed.
(1)
Santosh Waghmode said:
1 decade ago
When control is passes to the else block then it found the break statement and the BREAK statement pass the control to the last statement so the message in the printf() function is not printed even one time.
Rohit said:
1 decade ago
Can someone please tell me why the output is 27 for the following code?
#include<stdio.h>
int main()
{
int b=5;
int c= ((b++) + (++b) + (++b) + (++b));
printf("%d",c);
return 0;
}
#include<stdio.h>
int main()
{
int b=5;
int c= ((b++) + (++b) + (++b) + (++b));
printf("%d",c);
return 0;
}
Vadivel said:
7 years ago
#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=18; x++)
{
if(x<5)
printf("\nIndiaBIX");
else
break;
printf("\nIndiaBIX");
}
return 0;
}
Output is 12.
Please explain.
int main()
{
int x;
for(x=-1; x<=18; x++)
{
if(x<5)
printf("\nIndiaBIX");
else
break;
printf("\nIndiaBIX");
}
return 0;
}
Output is 12.
Please explain.
(3)
Priyanka Rawat said:
1 decade ago
Yes, the control does not go to print statement as before it break statement is given, and if we remove break keyword the word will get get printed 6 times... -1, 0, 1, 2, 3, 4.. as x<5 is given.
Nitin sagar said:
1 decade ago
Once if statement is false.
The control will move to the else block and the break statement.
Present in the else block will pass the control out of the body of the loop,
So nothing gets printed.
The control will move to the else block and the break statement.
Present in the else block will pass the control out of the body of the loop,
So nothing gets printed.
Bhavna Bhoir said:
9 years ago
Break statement is used to take control of execution abruptly out of the loop.
When continue statement is executed, then the control of execution simply continue to next iteration of the loop.
When continue statement is executed, then the control of execution simply continue to next iteration of the loop.
Vaibhav said:
1 decade ago
for (x<5) five times the control will go t starting of loop due to continue. And after for the else condition the break occurs so control will go out of loop so there wont be any printing
Hitesh Soni said:
1 decade ago
Continue takes the control to the beginning of the loop. Therefore as far as x<5, nothing happens.
As soon as value of x is 5,break statement takes the control outside the loop body.
As soon as value of x is 5,break statement takes the control outside the loop body.
Vaibhav said:
1 decade ago
Please anyone can explain me this program:
#include<stdio.h>
void main()
{
int s=0;
while(s++<10)
{
if(s>3&&s<10)
continue;
printf("\n%d\t",s);
}
}
#include<stdio.h>
void main()
{
int s=0;
while(s++<10)
{
if(s>3&&s<10)
continue;
printf("\n%d\t",s);
}
}
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers