Hello World Code


C Hello World Code and Implementation

Let's have a look at a basic program that prints the words "Hello World."

#include<stdio.h> #include<conio.h> /* includes header files */ void main() { clrscr(); /* clear user screen */ printf("Hello World!"); /* printing hello world */ getch(); /* hold the output screen */ }

output:

Hello World!

Take a look at the many sections of the above-mentioned software.

  • #include is a preprocessor command that instructs a C compiler to include the stdio.h file before proceeding to real compilation.
  • The main function, int main(), is where the programme execution begins.
  • The next line, /*...*/, will be disregarded by the compiler and has been added to the programme to add more comments. As a result, such lines are referred to as comments in the software.
  • The next line, printf(...), is a C function that displays the message "Hello, World!" on the screen.
  • The next line, return 0;, returns the value 0 and ends the main() function.

C Program Compilation and Execution

Let's look at how to save the source code to a file, build it, and run it. The easy steps are as follows: −

  • Add the above-mentioned code to a text editor.
  • Hello.c is the name of the file you should save it as.
  • Open a command prompt and navigate to the location where the file was saved.
  • To compile your code, type gcc hello.c and press enter.
  • If your code is error-free, the command prompt will forward you to the next line and create an executable file called a.out.
  • Type a.out to run your application now.
  • The output "Hello World" will be printed on the screen.