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 11 of 15.
Aminul said:
1 decade ago
#include<stdio.h>
int main()
{
int b=5;
int c= ((b++) + (++b) + (++b) + (++b));
printf("%d",c);
return 0;
}
I think the output will be 5+7+8+9 = 29.
int main()
{
int b=5;
int c= ((b++) + (++b) + (++b) + (++b));
printf("%d",c);
return 0;
}
I think the output will be 5+7+8+9 = 29.
Karan said:
1 decade ago
When condition will satisfy means x<5 is true then break statement will be executed. And then control will not transfer on printf statement.
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.
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();
}
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).
Ramsan said:
1 decade ago
After the break statement, It will come out of the loop. Then it will not going to print IndiaBix.
Dharmesh said:
1 decade ago
For printing the statement either it should be in if or in else block.
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.
Mansi sharma said:
1 decade ago
x is declared as integer so it can not be initialised as x=-1 so program won't run.
Arnav Bijalwan said:
1 decade ago
Continue statement transfers control to next iteration. Hence when condition (x<5) gets true, control jumps to next iteration. When x becomes 5, condition in if statement becomes false and it executes else part where it encounters break statement and jumps out of loop.
Hence control never encounters the printf statement and thus, it is executed 0 times. Hence the option C is correct.
Hence control never encounters the printf statement and thus, it is executed 0 times. Hence the option C is correct.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers