这是什么的sizeof(功能(参数))的回报? [英] What does sizeof (function(argument)) return?
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/492384/how-to-find-the-sizeofa-pointer-pointing-to-an-array\">How找到的sizeof(指针指向数组)结果
在使用功能的sizeof 输出
块引用>程序的输出中会是什么
的#include&LT;&stdio.h中GT;INT乐趣(字符*一){
的printf(%d个\\ N的sizeof(一));
返回1;
}诠释主(){
所以char a [20];
的printf(%d个\\ N的sizeof(FUN(一)));
返回0;
}
解决方案除经变长数组,
的sizeof
不计算其操作数。所以它只会产生的大小乐趣(一)
键入即的的sizeof(INT)
(不调用该函数)。
C11(n1570)§6.5.3.4的
的sizeof
和_Alignof
运营商
2 ...]如果操作数的类型是可变长度数组类型,操作数被评估;否则,操作数未评价,结果是一个
整型常量。
块引用>Possible Duplicate:
How to find the sizeof(a pointer pointing to an array)
Output of using sizeof on a functionWhat will be the ouput of program
#include <stdio.h> int fun(char *a){ printf("%d\n",sizeof(a)); return 1; } int main(){ char a[20]; printf("%d\n",sizeof (fun(a))); return 0; }
解决方案Except with variable length arrays,
sizeof
does not evaluate its operand. So it will just yield the size offun(a)
type, i.e.sizeof(int)
(without calling the function).C11 (n1570) §6.5.3.4 The
sizeof
and_Alignof
operators2 [...] If the type of the operand is a variable length array type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an integer constant.
这篇关于这是什么的sizeof(功能(参数))的回报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!