pigletwithcurls
pigletwithcurls

Reputation: 57

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!

Upvotes: 0

Views: 981

Answers (1)

Yuriko
Yuriko

Reputation: 586

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.

Upvotes: 3

Related Questions