Advertisement

Your First C Program

C Language Getting Started 📅 May 2026 ⏱ 2 min read 🆓 Free

Your First C Program — Hello World

Every programmer starts here. Let us write "Hello, World!" and understand every single character.

c
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    printf("I am learning C at CodeKaFunda!\n");
    return 0;
}
▶ Output
Hello, World!
I am learning C at CodeKaFunda!

Line-by-Line Explanation

LineWhat it means
#include <stdio.h>Includes Standard Input/Output library — provides printf() and scanf()
int main()The main function — C program ALWAYS starts executing from here
{ }Curly braces — define the beginning and end of a block of code
printf("text\\n")Prints text to screen. \\n = newline (like pressing Enter)
return 0;Returns 0 to OS = program ran successfully (0 = no error, 1 = error)

A Better First Program — With User Input

c
#include <stdio.h>

int main() {
    char name[50];   // array to store name
    int  age;
    
    printf("Enter your name: ");
    scanf("%s", name);          // read string input
    
    printf("Enter your age: ");
    scanf("%d", &age);          // read integer input
    
    printf("Hello, %s! You are %d years old.\n", name, age);
    printf("Welcome to C programming!\n");
    
    return 0;
}
▶ Output
Enter your name: Arjun
Enter your age: 17
Hello, Arjun! You are 17 years old.
Welcome to C programming!

Common Beginner Mistakes

MistakeProblemFix
Missing semicolon ;Compile error: expected ;Every statement must end with ;
Printf not printfUndefined function errorC is case-sensitive! Use lowercase
Forgetting #includeprintf not recognizedAlways add #include <stdio.h> at top
Missing & in scanfProgram crash/wrong outputUse &variable in scanf (except strings)
📌 Note: Save your file with .c extension: hello.c. If saved as .txt, the compiler will not recognize it.
Advertisement
← Back to C Language Index