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 13 of 15.
Sam said:
1 decade ago
Continue always takes the control back to the beginning of the loop and thus the value of x keeps on incrementing until it reaches the value 5. Once it becomes 5, the if condition fails and thus else comes into the picture. In the else block there is a break statement and hence entering into else makes the control to come come out of the for loop and point to the very next statement outside the for loop. Since there is no other printf statement. The whole of the program does not print IndiaBix.
Kondorpa said:
1 decade ago
can anyone please explain me the output?
#include<stdio.h>
main()
{
int p=5;
printf(" %d %d %d ",p,p++,++p);
}
Output is, as per indiabix.com compiler is 7 6 7
#include<stdio.h>
main()
{
int p=5;
printf(" %d %d %d ",p,p++,++p);
}
Output is, as per indiabix.com compiler is 7 6 7
Ashish Sawant said:
1 decade ago
Here for(x=-1), therefore the IndiaBix is printed 0 times.
Uday kumar said:
1 decade ago
@Murugesan @Vipin dhawan.
I has little bit query you guys answered for @Rohit question.
When it is b++ there will be no change in the value.
for ++b the value get increased by 1.
OK.
Let us take you are right for a while then,
for(i=-1;i<10;i++)
In this case what will be occur? I mean what will happens here for i++ whether it will increase or won't change.
I has little bit query you guys answered for @Rohit question.
When it is b++ there will be no change in the value.
for ++b the value get increased by 1.
OK.
Let us take you are right for a while then,
for(i=-1;i<10;i++)
In this case what will be occur? I mean what will happens here for i++ whether it will increase or won't change.
SAGAR RANPISE said:
1 decade ago
Here in the program, we have a integer variable. And a integer variable has the tendency to convert negative number. i.e. "signed number" into a positive no. i.e. "unsigned number". due to which the value -1 after converting into a positive no obviously becomes greater than 5 ;
And as there is a break statement after the 'else' statement the program terminates.
And as there is a break statement after the 'else' statement the program terminates.
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.
Bhavin Patel said:
1 decade ago
If condition of the for loop becomes false then loop will be terminated. So, INDIABIX will print 0 times.
Chirala anil kumar said:
1 decade ago
In this program increment the x value up to x = 5 after that if condition false come out of the loop. Nothing printed.
Nitika said:
1 decade ago
Till the time x is less than 5 it will satisfy the if condition and will move to continue. And we know that when continue is encountered the loop moves to its starting i.e. here it will go back to for loop.
And when if condition will fail i.e when x>5 the else part will be executed according to which break statement will be encountered and when break is encountered the loop moves to the first statement after that loop.
Therefore here it will go out off or loop. And hence printf will never get executed.
And when if condition will fail i.e when x>5 the else part will be executed according to which break statement will be encountered and when break is encountered the loop moves to the first statement after that loop.
Therefore here it will go out off or loop. And hence printf will never get executed.
Premalatha said:
1 decade ago
Guys please anyone can explain me!!!
void main()
{
int i;
i=1;
i=i+2*i++;
printf("%d",i);
}
Output = 4.
void main()
{
int i;
i=1;
i=i+2*i++;
printf("%d",i);
}
Output = 4.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers