During the interview, the examiner asked RT questions and thought the questions were relatively good, so he wrote them out and shared them.
As you know, the variables in the struct are char, int, long, short, and unallocated addresses.
See the following code:
# Include
# Include
# Include
Typedef struct {
Char;
Int B;
} Test_struct_t;
Int
Main (int argc, char * argv [])
{
Test_struct_t A, B;
A. a = 0;
A. B = 0; test_struct_t B;
Memset (& B, '\ 0', sizeof (B ));
If (0 = memcpy (& A, & B, sizeof ())){
Printf ("struct A is euqal struct B ");
} Else {
Printf ("struct A is uneuqal with struct B ");
}
Return 0;
}
With development experience, you can immediately state truct A is uneuqal with struct B because of the bytes of the struct.
A only clears char a according to the natural alignment principle, but the content of the next three bytes is random. B is used to clear the entire memory area, so the two are not equal in most cases,
Therefore, we can conclude that the struct cannot be compared using the memcpy function!