Why whole structure can not be compared in C, yet it can be copied?

后端 未结 6 1669
感情败类
感情败类 2020-12-16 18:08

Why whole structure can not be compared in C yet it can be copied? In other words, Why comparison in below program does not work? It does not print string.

#         


        
6条回答
  •  既然无缘
    2020-12-16 18:38

    But if you pass your value to a string, will it work?

    void Comparethisvalue(emp a, emp b) 
    {
        if(a.n.tostring()+a.age.tostring() == b.n.tostring()+b.age.tostring())
          return true; 
    }
    

    in code you can call

    if(Comparethisvalue(e1, e2))
    {
      //do something
    }
    

    Or you can implicit do it:

    void Comparethisvalue(emp a, emp b) 
    {
      if(a.n == b.n && a.age == b.age)
        return true; 
    }
    

提交回复
热议问题