Project

General

Profile

Feature #2462 ยป testx.c

Evgeny Novikov, 03/28/2013 12:16 PM

 
#include <stdio.h>
#include <stdlib.h>

struct A
{
int x;
} var_global;
struct B
{
int y;
};

int main()
{
/* Case 1. Casting of heap address. */
struct A *var_local1 = (struct A *)malloc(sizeof(struct A));
struct B *var_local2 = (struct B *)var_local1;
printf("The same addresses of different fields of different structures: %p %p\n", &var_local1->x, &var_local2->y);

/* Case 2. Casting of global variable address. */
var_local2 = (struct B *)&var_global;
printf("The same addresses of different fields of different structures: %p %p\n", &var_global.x, &var_local2->y);

return 0;
}
    (1-1/1)