Your expectation is wrong. A
is a float*
, so its size will be sizeof(float*)
, regardless of how you actually allocate it.
If you had a static array – i.e. float A[100]
, then this would work.
Since this is C++, use std::array
or std::vector
.
Worst case, use new[]
. Definitely don’t use malloc
.