sizeof works unusual at c++ after array creation [duplicate]

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.

Leave a Comment