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
#include <stdio.h>
#include <conio.h>
int main() {
clrscr();
printf("Hello, World!\n");
getch();
return 0;
}
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
Let's break down the code to understand what's happening:
#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().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.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.return 0;
, is a return statement that tells the operating system that the program has finished executing successfully.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.
To run the "Hello, World!" program in Turbo C++, you can follow these steps:
".c"
extension (e.g. "hello.c")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.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.