简体   繁体   English

C ++ uint8_t数组长度

[英]C++ uint8_t array length

I trying to get the size of array, but I gets funny results: 我试图获取数组的大小,但得到有趣的结果:

sizeof(new uint8_t[1]) gives me 4 while sizeof(uint8_t) gives me 1. sizeof(new uint8_t [1])给我4,而sizeof(uint8_t)给我1。

How do i get the size of an uint8_t array? 我如何获得uint8_t数组的大小?

new uint8_t[1] is a pointer, not an array. new uint8_t[1]是指针,而不是数组。

How do i get the size of an uint8_t array? 我如何获得uint8_t数组的大小?

For an array of N elements, the size in bytes is 对于N元素的数组,以字节为单位的大小为

sizeof(uint8_t[N]);

or 要么

N * sizeof(uint8_t);

However, if uint8_t exists, it will be one byte; 但是,如果uint8_t存在,则为1个字节;否则为0。 so in this case the array size is just N . 因此在这种情况下,数组大小仅为N

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM