简体   繁体   中英

Error in compiling hello world in c

I am a beginner in learning c although I took two java courses at school. I just started learning c with "The C Programming" book.

I am trying to compile my first program, "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(). 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.

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

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

EXIT_SUCCESS is defined in stdlib . It means that the application successfully ended. Its value is usually 0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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