Conversion of integer pointer to integer

后端 未结 4 738
春和景丽
春和景丽 2021-01-17 21:43

Tried following code to check what happens when we convert integer pointer to a integer .

 #include
 #include
 int main()
 {
          


        
4条回答
  •  难免孤独
    2021-01-17 22:14

    Here you're printing out the memory address of a, but you're printing it as a signed decimal integer. It doesn't make too much sense as a format, because some high memory addresses, the exact boundary depending on your word size and compiler, will be printed as negative.

    The standard is to print it as an unsigned hexadecimal padded with zeroes to 8 or 16 characters (really, this is dependent on the exact word-size again). In printf, this would be %#08X, so the memory address 0x243 would be printed as 0x00000243.

提交回复
热议问题