Hello World program in C language
Let’s begin writing with our first program i.e Hello World
.
Type the following code in your editor or IDE:
// hello.c
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
And, now if you are in IDE you can click Run
button (in Windows) else run the hello.c
C program(in macOS or Linux) as
$ gcc hello.c -o hello # compile the C program
# run the compiled program as
$ ./hello
Hello, World!
Understanding Code
#include
is a preprocessor command that tells the compiler to include the contents ofstdio.h
file which provide standard input and output operations.- The
stdio.h
file contains functions such asscanf()
andprintf()
to take input and display output respectively. main()
function is the starting point of execution.printf()
is a library function to print formatted output to the screen.- The
return 0;
statement is the “Exit status” of the program which represents successful execution.return 1;
represent failure in execution.