求BYTE *byte数组个数
BYTE byte[6];
byte[0]=22;
byte[1]=22;
byte[2]=22;
byte[3]=22;
byte[4]=22;
byte[5]=22;
int bLength = sizeof(byte);
为什么上面代码sizeof(byte)返回的是4,这怎么理解?如果我是想求byte数组个数,该怎么求?
byte
[解决办法]
基础不够扎实啊, 朋友.
来自MSDN中的原文:
The operand to sizeof can be one of the following:
A type name. To use sizeof with a type name, the name must be enclosed in parentheses.
An expression. When used with an expression, sizeof can be specified with or without the parentheses. The expression is not evaluated.
When the sizeof operator is applied to an object of type char, it yields 1. When the sizeof operator is applied to an array, it yields the total number of bytes in that array, not the size of the pointer represented by the array identifier. To obtain the size of the pointer represented by the array identifier, pass it as a parameter to a function that uses sizeof. For example:
[解决办法]
数组传入函数后会被转换为指针。
所以你在函数内sizeof(functionByte);为4,也就是指针的大小。