programmingC Programminghello worldcoding

Your First C Program: Hello, World!

By Swann
Picture of the author
Published on
Your First C Program

Introduction

Embarking on the journey of C programming begins with writing the classic 'Hello, World!' program. This simple program provides a sneak peek into the syntax and structure of C, introducing beginners to the basic constructs of the language.

Breaking Down 'Hello, World!' in C

The Complete Program

#include<stdio.h>

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

Explanation

  • #include<stdio.h>: This line tells the compiler to include the standard input-output library which is necessary for using the printf function.
  • int main(): This line declares the main function where the program execution begins.
  • {: This symbol marks the beginning of the main function’s body.
  • printf("Hello, World!");: This line instructs the program to output the text "Hello, World!".
  • return 0;: This line indicates that the program executed successfully and returns control to the operating system.
  • }: This symbol marks the end of the main function’s body.

Writing, Compiling, and Running Your First C Program

Writing the Code

Use a text editor or an Integrated Development Environment (IDE) to write the above code and save the file with a .c extension, for example, hello_world.c.

Compiling the Code

Use a C compiler to compile the code. If you are using a terminal or command prompt, navigate to the directory containing the code and run:

gcc hello_world.c -o hello_world

Here, gcc is the compiler, hello_world.c is the source code file, and hello_world is the output file.

Running the Code

Execute the compiled code using the following command:

./hello_world

You should see Hello, World! printed to the screen.

Conclusion

The 'Hello, World!' program, albeit simple, introduces you to the basic syntax and structure of C programming. Understanding this foundational program sets the stage for you to explore more complex aspects of the C language, paving the way for developing more intricate applications, understanding algorithms, and diving deeper into the world of programming.


Additional Resources

Stay Tuned

Want to become a Next.js pro?
The best articles, links and news related to web development delivered once a week to your inbox.