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; }
9 Respuestas
+ 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.
0
Edit your description accurately if any missing..
= before line int a... Typing mistake?
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
0
So u r saying that delhi is the output?
0
If it there just +b, then Kolkata.
If it is ++b, then d=0, but c=-1 so output is Delhi..
0
Thanks for helping i understood 😊
0
You're welcome..
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..