WRITING FIRST C PROGRAM

Writing First C program

Writing your first C program is an exciting step towards becoming a programmer. Let's walk through the process of creating a simple "Hello, World!" program in C:

Open VS code and follow the instructions as followed.

 

  1. Crete a new file and named it as "hello.c", remember c as extension.
  2. Write the code in the file
    #include <stdio.h>
    
    int main() {
      printf("Hello World!");
      return 0;
    }
  3. Save the file and open terminal.
  4. write "gcc hello.c"
  5. it will create a new file, run the new file directly as "./newfilename", in our case it is a.out
  6. Volla, you can see the output "Hello World!" in your terminal
 

 

Lets understand the structure

  • #include <stdio.h>: This line includes the standard input-output library, which provides functions like printf for displaying output.

  • int main(): This is the starting point of the program. The main function is where the program's execution begins.

  • { and }: These curly braces define a block of code that belongs to the main function.

  • printf("Hello, World!\n");: This line uses the printf function to display "Hello, World!" on the screen. The \n represents a newline character, which moves the cursor to the next line after printing.

  • return 0;: This line indicates that the program has completed successfully and returns a status code of 0 to the operating system.