What will be the output of the following code?int i;for (i = 0; i < 5; i++) { if (i == 3) { break; } printf("%d ", i);}
Question
What will be the output of the following code?int i;for (i = 0; i < 5; i++) { if (i == 3) { break; } printf("%d ", i);}
Solution
The output of the code will be:
0 1 2
Here's the step by step explanation:
- The variable
iis initialized with a value of 0. - The
forloop starts and checks ifiis less than 5. Sinceiis 0, it is less than 5, so the loop continues. - Inside the loop, there's an
ifstatement that checks ifiis equal to 3. Sinceiis 0, it is not equal to 3,
Similar Questions
What will be the output of the following code?#include <stdio.h>int main() { int i = 0; for (; i < 5; ) { printf("%d ", i); i++; } return 0;}
Consider the following code. What is the output?#include <stdio.h>int main() { int x = 5, y = 0; for (int i = 0; i < 5; i++) { y += x; if (y > 10) break; } printf("%d\n", y); return 0;}
What is the output of the code given below?#include <stdio.h> void main() { int i; for (i = 5; i < 10; i++); printf("%d ", i);}Options5105 6 7 8 99
CWhat is the output of the following piece of code?int i;i = 10;while (i < 20){ printf("%d", i % 2); i++;}
What is the output for the following code?12345678910111213#include <stdio.h> int main() { int i = 1; while (i <= 10) { if (i % 5 == 0) { i++; continue; } printf("%d ", i); i++; } return 0; }
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.