The problem is that the sizeof
operator checks the size of it's argument. The argument passed in your sample code is WCHAR*
. So, the sizeof(WCHAR*) is 4. If you had an array, such as WCHAR foo[23]
, and took sizeof(foo)
, the type passed is WCHAR[23]
, essentially, and would yield sizeof(WCHAR) * 23
. Effectively at compile type WCHAR*
and WCHAR[23]
are different types, and while you and I can see that the result of new WCHAR[23]
is functionally equivalent to WCHAR[23]
, in actuality, the return type is WCHAR*
, with absolutely no size information.
As a corellary, since sizeof(new WCHAR[23])
equals 4 on your platform, you're obviously dealing with an architecture where a pointer is 4 bytes. If you built this on an x64 platform, you'd find that sizeof(new WCHAR[23])
will return 8.