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
| Line | What 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
| Mistake | Problem | Fix |
|---|---|---|
| Missing semicolon ; | Compile error: expected ; | Every statement must end with ; |
| Printf not printf | Undefined function error | C is case-sensitive! Use lowercase |
| Forgetting #include | printf not recognized | Always add #include <stdio.h> at top |
| Missing & in scanf | Program crash/wrong output | Use &variable in scanf (except strings) |
📌 Note: Save your file with
.c extension: hello.c. If saved as .txt, the compiler will not recognize it.