|
|
struct typeA
{
int a;
};
struct typeB
{
int a;
};
struct typeC
{
float a;
};
int main(int argc, char *argv[])
{
struct typeA x, x1;
struct typeB y;
struct typeC z;
x = x1; // OK, same type !
x = y; // Bad ! DIFFERENT type
x = z; // Bad ! DIFFERENT type
}
|
When you compile the program, you will get error messages for the statements:
x = y;
x = z;
type1.c:24: error: incompatible types when assigning to type 'struct typeA'
from type 'struct typeB'
type1.c:25: error: incompatible types when assigning to type 'struct typeA'
from type 'struct typeC'
|
Reason:
|
|
|
In the above example, struct typeA and struct typeB have the same structure