Cover Image for First C Program
52 views

First C Program

Creating your first C program is a simple and exciting way to get started with C programming. Here’s a step-by-step guide on how to create and run a basic “Hello, World!” program in C:

  1. Install a C Compiler:
  • Before you can write and run C programs, you need a C compiler. Popular C compilers include GCC (GNU Compiler Collection), Clang, and Microsoft Visual C++ (for Windows). Make sure you have a C compiler installed on your system.
  1. Open a Text Editor:
  • You can use any text editor to write your C code. Common text editors include Notepad (Windows), Visual Studio Code, Sublime Text, Atom, and many others.
  1. Write Your C Code:
  • Open your text editor and create a new file. Write the following C code to print “Hello, World!” to the console:
C
 #include <stdio.h>

 int main() {
     printf("Hello, World!\n");
     return 0;
 }
  • This program includes the stdio.h header for input and output functions and defines a main function, which is the entry point of the program. The printf function is used to display “Hello, World!” on the console.
  1. Save Your C File:
  • Save the file with a .c extension. For example, you can name it hello.c.
  1. Compile Your C Program:
  • Open your command prompt or terminal.
  • Navigate to the directory where you saved your hello.c file using the cd command (change directory).
  • Compile your program using the C compiler. For GCC, you can use the following command:
Bash
   gcc hello.c -o hello
  • This command tells GCC to compile hello.c and generate an executable named hello (you can choose a different name if you prefer).
  1. Run Your C Program:
  • After a successful compilation, you can run your program using the following command:
Bash
 ./hello
  • You should see the output on your console:
Plaintext
 Hello, World!

Congratulations! You’ve just created and run your first C program. This “Hello, World!” program is a simple introduction to C programming and serves as the starting point for more complex projects and learning opportunities in the C language.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS