In this example, we will learn to print “Hello, World”

#include <stdio.h>
int main() {
   printf("Hello, World");
   return 0;
}
  • The #include is a preprocessor command that tells the compiler to include the contents of stdio.h (standard input and output) file in the program. This is a standard input-output file that contains the definitions of common input-output functions such as scanf() and printf(). In the above program we are using printf() function.
  • If we use the printf() function without writing #include <stdio.h>, the program will not compile.
  • int main()- The execution of a C program starts from the main() function. Every C program must have this function. The 0 return value of this function represents successful execution of program while the return value 1 represents the unsuccessful execution of program.
  • printf() is a library function to send formatted output to the screen. This function displays the content within double quotes as it is on the screen.
  • return 0 – It means successful execution of main() function. The C program ends with this statement.

Compile and Execute C Program

  1. Open a text editor and add the above-mentioned code.
  2. Save the file as filename.c
  3. Open a command prompt and go to the directory where you have saved the file.
  4. Type gcc filename.c and press enter to compile your code.
  5. type ./a.out to execute your program.
  6. You will see the output “Hello, World” printed on the screen.
gcc filename.c
./a.out
output:- Hello, World
Sharing is Caring
Load WordPress Sites in as fast as 37ms!
Scroll to Top