The "Hello, World!" program is a classic and simple program that is often used to introduce a new programming language. The program simply prints the message "Hello, World!" to the screen. In the C programming language, the "Hello, World!" program is typically written as follows:
For Turbo C++ Compiler
If you are using Turbo C++, you need to include conio.h
header file and call clrscr();
function at beginning and getch();
function at end.
C
#include <stdio.h>
#include <conio.h>
void main(){
clrscr();
printf("Hello World");
getch();
}
For GCC
C
#include <stdio.h>
void main(){
printf("Hello World");
}
Output
Hello World
- 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 theprintf()
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.
Learning C programming can seem daunting at first, but starting with a simple program like "Hello, World!" can help you to understand the basics of the language and build a solid foundation for more advanced programming. So, dive in and start experimenting with the language. Happy coding!