main()在C/C++中应该返回什么?
main()函数的返回值表示程序是如何退出的。程序正常退出时,返回值为零。如果代码有错误、故障等,将以非零的值退出。
在C++语言中,main()函数可以没有返回值。默认情况下,它会返回零。
以下是C语言中main()函数的语法:
int main() {
….
return 0;
}以下是C语言中main()函数的一个示例:
示例
#include <stdio.h>
int main() {
int a = 10;
char b = 'S';
float c = 2.88;
a = a+b;
printf("Implicit conversion from character to integer : %d\n",a);
c = c+a;
printf("Implicit conversion from integer to float : %f\n",c);
return 0;
}输出
Implicit conversion from character to integer : 93 Implicit conversion from integer to float : 95.879997
在上面的程序中,main函数有业务逻辑。有三个变量a、b和c,其中a保存a和b的和。变量c保存c和a的和。main函数返回0。
a = a+b;
printf("Implicit conversion from character to integer : %d\n",a);
c = c+a;
printf("Implicit conversion from integer to float : %f\n",c);
return 0;
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C程序设计
C++
C#
MongoDB
MySQL
Javascript
PHP