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;
}
Infinite times
11 times
0 times
10 times
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
142 comments Page 8 of 15.

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;
}

Agi said:   1 decade ago
int i=1
for(i=-1;i<=10;1++)
Then how it calculate -1 in for loop ?
Then how many it print?
Please explain this.

Himanshu said:   1 decade ago
Hi agi. No matter you take value of i=1 or something else only the value inside the loop will be executed. So take i=1 or 100 or 200 loop will work for i=-1.

Keshav saini said:   1 decade ago
Here printf ("IndiaBIX") ; is unreachable code. Because break keyword is stop the working of the block.

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.

Mayank said:   1 decade ago
Because when ever the break statement given in loop.

The loop terminates and control get out from the loop.

Amol said:   1 decade ago
The continue statement takes the control out of the loop for the next iteration and the break terminates the loop.

Srinu said:   1 decade ago
Break and continue statements does not allow to execute printf statement.

Harsha said:   1 decade ago
When break is encountered in loop then the control directly jumps to the first statement after the loop.

Ayodhya Prasad said:   1 decade ago
Since loop will execute until condition is true. After break it will not execute. Hence it will not print the IndiaBix.


Post your comments here:

Your comments will be displayed after verification.