问题描述
这可以从main()函数返回void,float,double,char,指针类型数据吗?
Is this possible to return void, float, double, char, pointer type data from main() function?
#include<stdio.h>
double main(){
printf("No may be not!!");
return 0.0;
}
#include<stdio.h>
float main(){
printf("No may be not!!");
return 0.0;
}
#include<stdio.h>
*main(){
printf("No may be not!!");
int n=9;
int *a;
a=n;
return (&a);
}
#include<stdio.h>
char main(){
printf("No may be not!!");
return '\0';
}
我的尝试:
我希望它们在codeblock中编译,虽然我收到错误消息。为什么?不能像上面那样主要返回任何内容吗?
What I have tried:
I want them compiled in codeblock though I got error message. Why? Can't main return anything as above?
推荐答案
程序启动时调用的函数是命名主要。该实现为此函数声明没有
原型。它应定义为返回类型 int 且没有
参数:
int main(void){/ *。 .. * /}
或带有两个参数(这里称为argc和argv,但任何名称可能都是使用
,因为它们是本地的它们被声明的函数):
int main(int argc,char * argv []){/ * ... * /}
或等价物,或者其他一些实现定义的方式。
The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent, or in some other implementation-defined manner.
你可以使用2个参数定义main int argc 和 char * argv [] ,或者什么也没有。但是根据所有现行标准,回报不能无效。
无论如何,一些编译器允许形式 void main(void){/ * ... * /} 作为私有扩展不符合标准。
You can define main with the 2 parameters int argc and char *argv[], or nothing. But the returns, as per all current standards, cannot be void.
Anyway some compilers allow the form void main(void) { /* ... */ } as private extension not standard compliant.
这篇关于返回主要类型()! !的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!