What does it mean and how? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

What does it mean and how?

int main(){ int a=6; char c= 5; printf("%d",!(a==c)); and output: 1 I am confused 🤯

1st Sep 2020, 2:40 AM
Kritima Tharu
Kritima Tharu - avatar
3 ответов
+ 1
Kritima Tharu Simple,see here a=6,c=5,and when u compare (a==c),it's false and !(a==c) is true, which is why it's true and prints value as '1', suppose you did (a! =c) which is true and !(a! =c) becomes false and prints as '0' ,hope this helped :) NOTE: you have to declare the char as char c='5'; https://code.sololearn.com/cxcSNpamZo81/?ref=app
1st Sep 2020, 2:54 AM
RuntimeERROR
RuntimeERROR - avatar
+ 3
Int a=5,b=6; Int c=a==b ; If i will print the. Value of c thn it will give false becoz 5==6 its false but if i write( not) operator ! Then it will give true !(5==6) now here bracket will solve first so 5==6 false then not operator work opposite for ture not operator give false so it will be true . But in your case u define 6 as a int but 5 as a char you can not compare int variable to char variable so here this will be false then ! Will change true value to false value to true so Output will be 1. If you will run this example it will give 0 as a Outputs becoz u can compare similar type of data . int a=6; char c= 5; printf("%d",(a==c)); Ig i write Float a=0.1 if(a==0.1) This will give false find reason .
1st Sep 2020, 3:55 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
It is too easy to understand, listen! The NOT operator is return true for false condition, and return false for true condition, here , int a = 6; char c = 5; Always they are false, so compiler gives you 1 for false condition.. I hope you understood! :)
1st Sep 2020, 8:36 AM
Rupali Haldiya
Rupali Haldiya - avatar