我试图获取数组的大小,但得到了有趣的结果:
sizeof(new uint8_t[1]) 给我 4 而 sizeof(uint8_t) 给我 1。
如何获取 uint8_t 数组的大小?
最佳答案
new uint8_t[1]
是指针,不是数组。
How do i get the size of an uint8_t array?
对于 N
元素的数组,字节大小为
sizeof(uint8_t[N]);
或
N * sizeof(uint8_t);
但是,如果uint8_t
存在,它将是一个字节;所以在这种情况下,数组大小仅为 N
。
关于C++ uint8_t 数组长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22513874/