首页 > 解决方案 > 空函数的大小

问题描述

我在 c 中遇到过 void 函数。而且我知道这些函数不会返回任何值,但会有一个返回语句。我试图用 sizeof 运算符查看函数的大小。打印的值为 1 作为 void 函数的大小。谁能解释一下 1 是函数的大小?

下面是我用过的程序。

#include <stdio.h>

void my_func() 
{
   printf("From void my_function\n");
   return ;
}

int func()
{
    printf("From int func\n");
    return 0;
}

int main() 
{
   printf("Size of void function : %lu\n",sizeof(my_func())); // 1 is printed
   printf("Size of integer function : %lu\n",sizeof(func())); // 4 is printed

   return 0;
}

标签: c

解决方案


推荐阅读