0

What if the output of the program below?

#include <stdio.h> int main() { int a = 1, b = -1, c= 0, d; d=++a && +b || c--; if (d) printf("Kolkata \n"); else if(c) printf("Delhi \n"); else printf("Bangalore \n"); return 0; }

17th Feb 2020, 4:25 PM
Rimjhim Pandey
Rimjhim Pandey - avatar
8 Antworten
+ 1
d= (++a && +b) || c-- =( 2 && -1) || 0 = (1) || 0 = 1 || 0 d= 1 So Kolkata. If it is d= (++a && ++b) || c-- //c=c-1=-1 =( 2 && 0) || 0 = 0 || 0 = 0 And c=-1 So Delhi. IN C, other than zero is considered as true. Operators are evaluated from left to right if there is equal priority.
17th Feb 2020, 4:48 PM
Jayakrishna 🇮🇳
0
Edit your description accurately if any missing.. = before line int a... Typing mistake?
17th Feb 2020, 4:44 PM
Jayakrishna 🇮🇳
0
No this was only the question so i was confused 🤔 i m getting d=0 but i dont know what to do with it whether the output isdelhi as it is given c=0
17th Feb 2020, 4:47 PM
Rimjhim Pandey
Rimjhim Pandey - avatar
0
So u r saying that delhi is the output?
17th Feb 2020, 4:58 PM
Rimjhim Pandey
Rimjhim Pandey - avatar
0
If it there just +b, then Kolkata. If it is ++b, then d=0, but c=-1 so output is Delhi..
17th Feb 2020, 5:02 PM
Jayakrishna 🇮🇳
0
Thanks for helping i understood 😊
17th Feb 2020, 5:03 PM
Rimjhim Pandey
Rimjhim Pandey - avatar
0
You're welcome..
17th Feb 2020, 5:04 PM
Jayakrishna 🇮🇳
0
~ swim ~ Yes. Just typo mistake. In 2nd case also I copy pasted from 1st one, and edited only so not seen that. Thanks for correction. I think this question is from challenge section question. Question asking about explanation of output what & why..
17th Feb 2020, 6:00 PM
Jayakrishna 🇮🇳