Someone explain me, how the output 678 and how this code works. Code Challange question | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

Someone explain me, how the output 678 and how this code works. Code Challange question

#include <stdio.h> int main() { int i =6; int max =9; for(;;){ if(i>=max) break; printf("%d",i++); } return 0; } Output = 678

14th Jun 2023, 2:09 AM
Yogesh Pulami
Yogesh Pulami - avatar
3 Respuestas
+ 5
The code you shared has "for()" loop. -> for() loop... is loop that is used to repeat a block of code until the specified condition is met -> the assign value of i = 6 -> max assign value = 9 If statement is asking (i>=max) means -> (6>=9) Break statement has increment (i++) # here you keep incrementing i value as +1 until you reach max (i.e, i = 6, i = 6 + 1 = 7, i = 7 + 1 = 8)... & max = 9, that break statement requires you to do, break at 9 & its not in your "if statement." So, your Output is 6, 7, 8.
14th Jun 2023, 2:24 AM
D Shah 🎯⏳️
D Shah 🎯⏳️ - avatar
+ 3
1. The variable i is initialized to 6 and the variable max is initialized to 9. 2. The for loop starts and runs indefinitely because there are no conditions specified in the loop header. 3. Inside the loop, an if statement checks if the value of i is greater than or equal to the value of max. If it is, the loop is exited using the break statement. 4. If the value of i is less than the value of max, the value of i is printed using the printf() function and then incremented by 1 using the post-increment operator (i++).
16th Jun 2023, 9:39 AM
Vaibhav
Vaibhav - avatar
+ 1
Supplemental: dostuff(i++) means first do stuff, then i++ If you wanted to increment before doing stuff, you'd use dostuff(++i) instead
14th Jun 2023, 4:09 AM
Orin Cook
Orin Cook - avatar