First Program in C

Welcome to the world of C! C is a powerful, general-purpose programming language that has been around for decades. It serves as the foundation for many modern languages like C++, Java, and Python. If you’re starting your programming journey, learning C is an excellent choice.

In this post, we will guide you through writing your first C program. Whether you’re a beginner or brushing up on the basics, this guide will help you get started.

Setting Up Your Environment

Before we write any code, ensure you have the following:

  1. A C Compiler: Install a compiler like GCC (GNU Compiler Collection) or use an IDE like Code::Blocks or Dev-C++.
  2. A Code Editor: Use an editor like Visual Studio Code, Sublime Text, or the editor included in your IDE.

Writing Your First C Program

  1. Open your code editor.
  2. Create a new file and name it hello_world.c.
  3. Add the following code:
#include <stdio.h>

int main() {
    // This is your first C program
    printf("Hello, World!\n");
    return 0;
}

Explanation of the Code

  • #include <stdio.h>: This is a preprocessor directive that includes the standard input-output header file.
  • int main(): The main function is the entry point of any C program.
  • printf("Hello, World!\n");: This command prints “Hello, World!” followed by a newline to the console.
  • return 0;: This indicates that the program executed successfully.

Compiling and Running Your C Program

  1. Save the file.
  2. Open a terminal or command prompt.
  3. Navigate to the directory where you saved the file.
  4. Compile the program by typing:
gcc hello_world.c -o hello_world
  1. Run the compiled program by typing:
./hello_world

You should see the output:

Hello, World!

Congratulations! You’ve successfully written, compiled, and executed your first C program.

What’s Next?

Now that you’ve written your first program, explore more C concepts like variables, loops, and functions. C is a versatile language that forms the backbone of many systems and applications.

Happy coding!

Previous
Next

More Amazing Post

Get 15GB free hosting with Infinity Free

  • January 23, 2025

hosting is a compulsory thing for publish a website....

author-avatar
Posted By nazir

Programming Languages and Their Frameworks

  • January 20, 2025

Programming languages and frameworks go hand-in-hand to simplify and...

author-avatar
Posted By nazir

Uses of C#

  • January 20, 2025

C# (pronounced as “C-Sharp”) is a versatile and powerful...

author-avatar
Posted By nazir
Scroll to Top