What's the proper use of printf to display pointers padded with 0s

后端 未结 9 2176
暖寄归人
暖寄归人 2021-01-31 14:32

In C, I\'d like to use printf to display pointers, and so that they line up properly, I\'d like to pad them with 0s.

My guess was that the proper way to do this was:

9条回答
  •  爱一瞬间的悲伤
    2021-01-31 15:13

    Use:

    #include 
    
    printf("0x%016" PRIXPTR "\n", (uintptr_t) pointer);
    

    Or use another variant of the macros from that header.

    Also note that some implementations of printf() print a '0x' in front of the pointer; others do not (and both are correct according to the C standard).

提交回复
热议问题