Performing operations on structures – functions
Except for assignment, there are no intrinsic operations for structures. To perform any operation on a single structure or with two structures, a function must be written to perform the desired operation.
For example, earlier, we mentioned a function that can be used to compare two structures for equality. This must be done component by component, as follows:
bool isEqual( struct Card c1 , struct Card c2 ) {
if( c1.suit != c2.suit ) return false;
if( c1.face != c2.face ) return false;
return true;
}
Notice that we did not compare every component of struct Card
in this function. We'd only have to do that for absolute comparison and when we need to compare each and every component of both structures. This just isn't necessary for our card
example.
Does it make sense to perform any or all mathematical operations on two structures? In general, no, but...