+ 7

#include<stdio.h> int main(){ int i=2,j=2; while(i+1?–i:j++) printf(“%d”,i); return 0; }

what will be the output?

22nd Mar 2018, 10:36 AM
Monaliza
Monaliza - avatar
10 Respostas
+ 10
while loop is wrong. check the C++ course and change it.
22nd Mar 2018, 11:37 AM
Manual
Manual - avatar
+ 8
just change one thing you'll get an answer..
24th Mar 2018, 2:57 PM
Monaliza
Monaliza - avatar
+ 7
if anyone of you interested, just solve this code.. print the output as 1..
22nd Mar 2018, 1:34 PM
Monaliza
Monaliza - avatar
+ 7
I know it is.. but someone have knowledge about this.. if you are the person who someone.. you can solve this..
24th Mar 2018, 2:15 PM
Monaliza
Monaliza - avatar
+ 6
Output: 1 Consider the while loop condition: i + 1 ? — i : ++j In first iteration: i + 1 = 3 (True) So ternary operator will return -–i i.e. 1 In c 1 means true so while condition is true. Hence printf statement will print 1 In second iteration: i+ 1 = 2 (True) So ternary operator will return -–i i.e. 0 In c zero means false so while condition is false. Hence program control will come out of the while loop.
22nd Mar 2018, 1:29 PM
Monaliza
Monaliza - avatar
+ 6
The while loop will always be true umm..
24th Mar 2018, 2:54 PM
Ananya Srivastava
Ananya Srivastava - avatar
+ 5
Output will be 22222... and it is infinite loop..... since the while condition is conditional operator it performs the logic without terminating . The print statement is i, where i is 2...it doesnt changes since we didn't assign it ...Is this correct I also executed
22nd Mar 2018, 12:26 PM
Shivadharshini Nagaraju
Shivadharshini Nagaraju - avatar
+ 4
WHAT have u created an error mess
22nd Mar 2018, 11:22 AM
JonneSir
JonneSir - avatar
+ 4
And so it will go in infinite loop and will print 2 infinitely
24th Mar 2018, 2:55 PM
Ananya Srivastava
Ananya Srivastava - avatar
0
Idk
2nd Feb 2022, 7:08 AM
Jagan Karunagaran