Your First C Program - Hello, World!
Introduction
Congratulations on starting your journey into C programming! "Hello, World!" is the traditional first program that beginners write when learning a new programming language. In this tutorial, you'll create your first C program, which will display "Hello, World!" on the screen.
Writing the "Hello, World!" Program
Open a text editor and create a new file, and then enter the following C code:
#include <stdio.h>
int main() {
printf("Hello, World!\\n");
return 0;
}
This code is a simple C program. It includes the standard input/output library (stdio.h
). The program defines a main
function, which is the entry point of every C program. Inside the main
function, the printf
function is used to display "Hello, World!" on the screen. Finally, the return 0
statement is used to indicate that the program has run successfully.
Compiling and Running the Program
Now that you've written the code, you need to compile and run it:
- Save the file with a
.c
extension, such ashello.c
. - Open your command prompt or terminal.
- Navigate to the directory where you saved
hello.c
. - Compile the program using the following command:
gcc hello.c -o hello
- Run the program using this command:
./hello
If everything is set up correctly, you should see "Hello, World!" printed on the screen.
Conclusion
Writing and running your first C program is a significant milestone in your programming journey. "Hello, World!" is the first step in understanding the basic structure of C programs and how to compile and run them. From here, you can explore more complex C programming concepts and applications.