The "Hello, World!" program is a classic and simple program that is often used to introduce a new programming language. In the C programming language, the "Hello, World!" program is typically written as follows

For Turbo C++ Compiler

C
#include <stdio.h>
#include <conio.h>

int main() {
    clrscr();
    printf("Hello, World!\n");
    getch();
    return 0;
}

For GCC Compiler

C
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

Let's break down the code to understand what's happening:

  • The first line, #include <stdio.h>, is a preprocessor directive that tells the compiler to include the contents of the standard input/output header file (stdio.h) in the program. This header file contains declarations for the standard input/output functions, such as printf().
  • The int main() line defines the main function of the program. This is the entry point of the program, and the code within the curly braces ({}) will be executed when the program runs.
  • The next line, printf("Hello, World!\n");, calls the printf() function to print the string "Hello, World!" to the standard output (usually the console). The \n at the end of the string is called a newline character, which causes the cursor to move to the next line after the string is printed.
  • The last line, return 0;, is a return statement that tells the operating system that the program has finished executing successfully.

Run in GCC Compiler

To compile and run the program, you can use a C compiler like GCC. On the command line, navigate to the directory where the source file is located, and then type gcc -o hello hello.c, this will create the binary file 'hello' that you can run. Once the compilation is finished, type ./hello to run the program.

Run in Turbo C++ Compiler

To run the "Hello, World!" program in Turbo C++, you can follow these steps:

  1. Open the Turbo C++ IDE (Integrated Development Environment) by double-clicking on the Turbo C++ icon or running the TC.exe file in the Turbo C++ installation folder.
  2. Go to the "File" menu and select "New" to create a new file. This will open an editor window where you can type in the C code for the "Hello, World!" program.
  3. Copy and paste or Type the code from the previous example into the editor window:
  4. Go to the "File" menu and select "Save As". Select "All files" and give your file a name with the ".c" extension (e.g. "hello.c")
  5. Go to the "Compile" menu and select "Compile" (or press F9 on the keyboard) to compile the program. This will check the code for any syntax errors. If there are any errors, they will be displayed in a separate window, and you will need to fix them before proceeding.
  6. If the program compiles successfully, go to the "Run" menu and select "Run" (or press Ctrl + F9) to execute the program.

The program will output "Hello, World!" on the screen. This simple program demonstrates the basic structure of a C program, and it can serve as a starting point for more complex programs.