I have two questions:
1: I do not remember, but I think before, the address was only 6 hexadecimal digits, now It is 10, I think It has something to do with OS architecture(mine is 64-bit), but I am not sure. Do you have any idea about this?
2: the ptr gives an address, but what about ptr2, is this an address too?
1. One hexadecimal digit represents 4 bits. That means a 32-bit number/address can need up to 8 hexadecimal digits while a 64-bit number/address can need up to 16 hexadecimal digits, but as always you can can leave out leading zeroes so fewer digits might be necessary when you write out the number.
Compare these two outputs:
1 2 3 4
int x;
std::cout << &x << std::endl;
int* p = newint;
std::cout << p << std::endl;
For me these print different amounts of digits.
2. ptr2 is a so called "null pointer". Null is a special value that you can give to pointers when they don't point to anything.
Arguably 'should' is a wrong word choice here.
An address is just a number, so leading zeroes don't mean anything.
And your example address is only 14 hexadecimal digits.
What matters in the end is sizeof(my_ptr).
To get more technical, the C++ standard doesn't guarantee a pointer is 64-bit if compiling as a 64-bit program, but most implementations (like VC++) will make extra guarantees such as that.
It's just like when you write a normal number in math. 0000000024 means the same thing as 00024 or 24. The leading zeroes has no meaning.
Note that I'm talking about math. If you write an integer literal starting with a zero C++ will interpret that as an octal (base 8) number.
Hexadecimal is often used to display binary data, because each digit corresponds exactly to 4 bits (2 digits = 1 byte), and it is therefore quite common that you see leading zeroes so that the number of digits corresponds to how many bits there are in the underlying data.
Exactly how the addresses are displayed seems to differ between different implementations. Microsoft's implementation seem to display the addresses in hexadecimal with leading zeroes, using upper case letters and without the 0x prefix.
std::format can print out pointer addresses, it has a format presentation type for pointers, though it currently requires a bit of a 'casting hack' to work: