C
Programming and Technical
How can we check whether the contents of two structure
variables are same or not?
Read Solution (Total 3)
-
- There is no way you can compare the two structure variables.
for Ex:
stucture test a, b;
if (a == b) // is wrong, we can't compare structure as whole. - 7 years agoHelpfull: Yes(0) No(0)
- The two structure variables need to be of same type.
we can check the equality of two structure variables by comparing them individually. - 7 years agoHelpfull: Yes(0) No(0)
- struct integers{
int a;
int b;
int c;
}e1,e2; // e1 and e2 are two structs.
so if you compare them directly like this:
if (e1 == e2){
// Code.
};
the compiler will be confused which one of the e1’s member (a,b or c) you want to compare against e2’s member, hence you have to compare each member separately like this:
// This comparison is for the struct 'integers'.
if(e1.a == e2.b){
// Code.
}; - 7 years agoHelpfull: Yes(0) No(0)
C Other Question