为什么在C语言中不能给函数传递void和一个参数?

问题描述 投票:-2回答:1
#include <stdio.h>

void fun();

int main(void) {
  fun(fun());
  return 0;
}

void fun()
{
  printf("function is called");
}

函数fun的返回类型是void。所以下面的语句应该是有效的,对不对!但是编译器会提出编译错误,因为函数fun的返回类型是void。

fun(fun())

但编译器却提出了编译错误,原因是 错误:参数类型'void'不完整。. 无法理解该错误的含义?

c function void return-type
1个回答
0
投票

我想你要的是这样的东西。

#include <stdio.h>

int fun(int arg);   // function takes one argument

int main(void) {
  fun(fun(1));      // use one argument when calling fun
  return 0;
}

int fun(int arg)
{
  printf("function is called\n");
  return 0;
}
© www.soinside.com 2019 - 2024. All rights reserved.