/* To build gcc int_align.c; ./a.out */ #include #include #include //#include #define VAR_TO_STR_BIN(x) \ obj_to_bin((char[sizeof(x) *CHAR_BIT + 1]){""}, &(x), sizeof(x)) char *obj_to_bin(char *dest, void *object, size_t osize) { const unsigned char *p = (const unsigned char *)object; p += osize; char *s = dest; while (osize-- > 0) { p--; unsigned i = CHAR_BIT; while (i-- > 0) { *s++ = ((*p >> i) & 1) + '0'; } } *s = '\0'; return dest; } int main() { int i_int; uintptr_t integer_value_pointer; integer_value_pointer = (uintptr_t)&i_int; long long int i_long_long; printf("Sizeof data : %ld, Address, of data %p, Address in Binary (look at " "lower bits), %s ", sizeof(i_int), &i_int, VAR_TO_STR_BIN(integer_value_pointer)); integer_value_pointer = (uintptr_t)&i_long_long; printf( "\n Sizeof data : %ld, Address, of data %p, Address in Binary (look at " "lower bits), %s ", sizeof(i_long_long), &i_long_long, VAR_TO_STR_BIN(integer_value_pointer)); char ch = 'a'; integer_value_pointer = (uintptr_t)&ch; printf( "\n Sizeof data : %ld, Address, of data %p, Address in Binary (look at " "lower bits), %s ", sizeof(ch), &ch, VAR_TO_STR_BIN(integer_value_pointer)); short s_num = 0xBEEF; integer_value_pointer = (uintptr_t)&s_num; printf( "\n Sizeof data : %ld, Address, of data %p, Address in Binary (look at " "lower bits), %s ", sizeof(s_num), &s_num, VAR_TO_STR_BIN(integer_value_pointer)); return 0; }