the if case in this code doesnt work while there is no syntax error

前提是你 提交于 2019-12-02 13:07:36

It is not like the first case doesn't work at all, it just works in a way which is not intended.

As per the code,

 if(s.name=="kolkata")  

is an attempt to compare the pointers themselves. It does not compare the content of the memory location pointer by these pointers.

Coming to the point where you were expecting syntax errors, quoting C11, chapter 6.5.9, the constraints of the Equality operator, (==)

  • both operands are pointers to qualified or unqualified versions of compatible types;

So,

if(s.name=="kolkata")  

is a perfectly valid and legitimate C code, from syntactical point of view. Logically, when you're expecting to compare the contents of the memory area pointer by the pointers, this code is useless and makes no sense.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!