这是什么的sizeof(功能(参数))的回报? [英] What does sizeof (function(argument)) return?

查看:272
本文介绍了这是什么的sizeof(功能(参数))的回报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  <一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 function

What 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 of fun(a) type, i.e. sizeof(int) (without calling the function).

C11 (n1570) §6.5.3.4 The sizeof and _Alignof operators

2 [...] 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆