简体   繁体   English

在C中编译Hello World时出错

[英]Error in compiling hello world in c

I am a beginner in learning c although I took two java courses at school. 尽管我在学校上过两门Java课程,但我还是学习c的初学者。 I just started learning c with "The C Programming" book. 我刚从“ The C Programming”一书开始学习c。

I am trying to compile my first program, "hello.c" 我正在尝试编译我的第一个程序“ hello.c”

I typed in as the book says: 我按书中所述输入:

#include <stdio.h>

main()
{
    printf("hello, world\n");
}

However, it says that I have to write the type specifier 'int' before main(). 但是,它说我必须在main()之前编写类型说明符'int'。 I'm trying to understand why this is so because the book dosen't indicate about the type specifier. 我试图理解为什么会这样,因为这本书没有指出类型说明符。

Thank you! 谢谢!

Your main function needs to return something, that's what the compiler is telling you. 您的main功能需要返回一些内容,这就是编译器告诉您的内容。

#include <stdio.h>
#include <stdlib.h>

int main() {
    printf("hello, world\n");
    return EXIT_SUCCESS;
}

EXIT_SUCCESS is defined in stdlib . EXIT_SUCCESSstdlib定义。 It means that the application successfully ended. 这意味着应用程序成功结束。 Its value is usually 0. 其值通常为0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM