全栈开发
C语言
【Q433】在C语言中,void 是什么意思

在C语言中,void 是什么意思

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 440 (opens in a new tab)

Author 回答者: shfshanyue (opens in a new tab)

void,空的意思,意即无需返回。

#include <stdio.h>
 
void print() {
  puts("hello, world");
  return;
}
 
int main() {
  print();
  return 0;
}

代码如上所示: return 没有返回任何东西,为其简便可以省略不写,以下两者是等价的

void print() {
  puts("hello, world");
  return;
}
 
void print() {
  puts("hello, world");
}

Author 回答者: yuetong3yu (opens in a new tab)

表示为空,跟 ts 一样的。