[8-bit] signed char: -127 to 127
[8-bit] unsigned char: 0 to 255
[16-bit]signed short: -32767 to 32767
[16-bit]unsigned short: 0 to 65535
[32-bit]signed long: -2147483647 to 2147483647
[32-bit]unsigned long: 0 to 4294967295
[64-bit]signed long long: -9223372036854775807 to 9223372036854775807
[64-bit]unsigned long long: 0 to 18446744073709551615
typedef int array[12];
int function(array t){
int size_of_t = sizeof(t)/sizeof(t[0]);
return size_of_t;
}
void main(){
array t = {1,1,1}; //remember: t= [1,1,1,0,...,0]
int a = function(t); //remember: sending t is just a pointer and equal to int* t
print(a); // output will be 1, since t will be interpreted as an int itselve.
}
所以这甚至不会返回不同的值。如果你定义了一个数组,然后试图获取数组的长度,使用sizeof。如果将数组发送给函数,请记住发送值只是第一个元素上的指针。但在情况一,你总是知道数组的大小。第二种情况可以通过定义两个函数而忽略一些性能来计算。定义function(数组t)和function2(数组t, int size_of_t)。调用“function(t)”通过一些复制工作测量长度并将结果发送给function2,在那里您可以对可变数组大小做任何想做的事情。