Why s1=!s2 ?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why s1=!s2 ??

#include<stdio.h> int main() { typedef struct { char ch; } st; st s1 = {'c'}; st s2 = s1; if(s1 == s2) printf("Successful"); return 0; // output Compile error

31st May 2021, 7:55 AM
NIKHIL JOSHI
NIKHIL JOSHI - avatar
3 Answers
+ 3
You cannot compare the struct, that is you can't apply the following: ==, !=, <, <=, >, >=. The best you can do is compare the member. In your case it could be if(s1.ch == s2. ch).
31st May 2021, 8:01 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 2
You are not supposed to compare the structs. You have to compare the values. So it should be: s1.ch == s2.ch
31st May 2021, 8:01 AM
Infinity
Infinity - avatar
0
Infinity CarrieForle yes now I got it. Thanks.
31st May 2021, 8:18 AM
NIKHIL JOSHI
NIKHIL JOSHI - avatar