0
0
Cprogramming~5 mins

Writing first C program

Choose your learning style9 modes available
Introduction

We write a first C program to learn how to tell the computer what to do using simple instructions. It helps us understand the basics of programming.

When you want to print a message on the screen.
When you want to learn how to start programming in C.
When you want to check if your computer can run C programs.
When you want to understand how a simple program is structured.
Syntax
C
#include <stdio.h>

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

#include <stdio.h> tells the program to use input/output functions like printf.

int main() is the starting point of the program.

Examples
This program prints a different greeting message.
C
#include <stdio.h>

int main() {
    printf("Hello, C learner!\n");
    return 0;
}
This program shows a welcome message to new programmers.
C
#include <stdio.h>

int main() {
    printf("Welcome to C programming!\n");
    return 0;
}
Sample Program

This program prints the message "Hello, world!" on the screen. It shows how to write a simple C program that runs and displays text.

C
#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}
OutputSuccess
Important Notes

Always end your printf strings with \n to move to the next line.

The return 0; means the program finished successfully.

Use a semicolon ; at the end of each instruction.

Summary

A C program starts with int main() function.

Use printf to show messages on the screen.

End each statement with a semicolon ;.