I'm trying to print a memory address in C, this is the code I'm using
#include <stdio.h> int main() { int v = 10; printf("Address of the v: %p\n",&v); return 0; } The output is supposed to start with 0x, but I don't have this thing, it shows this 0061FF14 I am using MingW32 gcc compiler I changed it to 64 and when I typed the code again the output is 000000A57A7FF67C
When I use https://www.onlinegdb.com/ the output is normal with 0x
My machine is 64 bit I am using vscode editor, how do I make the address appear as normal 0x
pspecifier is implementation defined. It's up to the implementation whether to include the0xor not.%pis largely intended for debugging. Addresses within a process are generally not even portable to other processes of the same system, let alone other systems, and that is why the format is left as implementation-defined rather than more fully specified by the C standard. If you want finer control over the formatting, you can convert an address to theuintptr_ttype (defined in<stdint.h>and use the fuller format modifications available with the integer types, including using thePRIxPTRmacro for the format defined in<inttypes.h>.#include <inttypes.h>andprintf("0x%" PRIXPTR "\n", (uintptr_t)pointer);. For myself, I prefer hex to be printed with0xABCD0123EF456789with the dip at the start for thexand the rest all full height. If you prefer lower-case alpha characters in your hex, usePRIxPTRinstead. You can specify how many digits to print using, for example,printf("0x%.12" PRIXPTR "\n", (uintptr_t)pointer)).