First C Program

Welcome to your first C program! Every programmer's journey begins with the classic "Hello, World!" program. It's like a friendly handshake between you and the programming world.

Let's dive right in and look at your first C program:

#include <stdio.h>

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

When you run this program, it will display:

Hello, World!

Breaking Down the Program

Let's understand each part of this program step by step:

1. The Header File

#include <stdio.h>
  • This line tells the compiler to include the standard input/output library
  • stdio.h contains functions like printf() that we use for displaying output
  • Think of it as importing a toolbox that contains useful tools for your program

2. The Main Function

int main() {
  • Every C program must have a main() function - it's the entry point of your program
  • When you run your program, execution starts from the main() function
  • int means this function will return an integer value
  • The curly braces {} contain the body of the function

3. The Printf Statement

printf("Hello, World!\n");
  • printf() is a function that prints text to the screen
  • The text inside double quotes "Hello, World!\n" is called a string
  • \n is a special character called a newline - it moves the cursor to the next line
  • Don't forget the semicolon ; at the end - it marks the end of a statement in C

4. The Return Statement

return 0;
  • This tells the operating system that the program executed successfully
  • 0 typically means "no errors occurred"
  • Non-zero values usually indicate that something went wrong

Now let's go ahead and write your first program on the right side editor. Go through the instructions on the top of the program and change the code accordingly. Once you are done please click on the Submit button to check the results.