#include #include typedef struct { int a; } A; typedef struct { int b; float c; } B; int main() { // Casting. Example 1 int a=3; float b=4.3; unsigned long l=LONG_MAX; printf("%d %f ", (int)b, (float)a); printf("%ld %hu\n", l, (unsigned short)l); // Casting. Example 2 int array[10]; int *p1 = &array[1]; int *p2 = &array[2]; printf("%d ", p2 - p1); // Prints 1 printf("%d\n", (char*)p2 - (char*)p1); // Prints 4 // Casting. Example 3 A sa; A *p_sa = &sa; //(B)sa; // -> Does not compile ("conversion to non-scalar type requested") ((B*)p_sa)->c = 5.6; // -> Compiles just fine even if ERRONEOUS //B* p_sb = p_sa; // -> Does not compile ("incompatible pointer types") B* p_sb = (B*)p_sa; printf("Wrong: %d %f\n", p_sb->b, p_sb->c); return 0; }