What is C Programming Language?
C is a programming language. We use it to give instructions to a computer.
It was made by Dennis Ritchie at Bell Labs in 1972. It is more than 50 years old, but it is still used everywhere: in operating systems, mobile phones, cars, washing machines and databases.
In this lesson you will learn what C is, why it is important, and how a C program runs.
What You Will Learn
- What C is, in simple words.
- Why C is called a middle-level and compiled language.
- Where C is used today.
- The basic structure of a C program.
- How to write your first C program.
- The 4 steps a C program goes through before it runs.
C Programming Language Explained
Exam definition: C is a general-purpose, procedural, middle-level programming language. It was developed by Dennis Ritchie at Bell Labs in 1972 to write the UNIX operating system.
What is a programming language?
A programming language is how we write code: the words (keywords) and rules we use to tell the computer what to do.
Different programming languages are used for different purposes:
- JavaScript is good for web development.
- Python is good for AI.
- C / C++ is good for programming microcontrollers.
Features of the C language
C has four main features. Remember these four words:
| Feature | Simple meaning |
|---|---|
| General-purpose | You can make almost any kind of program with it: games, calculators, operating systems. |
| Procedural | The program runs step by step, from top to bottom, using functions. |
| Compiled | The whole program is converted to machine code before it runs. |
| Middle-level | It is easy to read like a high-level language, and it can also control memory like a low-level language. |
Memory trick: C is a bridge. On one side is the human (easy language), on the other side is the machine (memory and hardware). C stands in the middle, so it is called a middle-level language.
Compiled vs interpreted languages
| Compiled (C, C++) | Interpreted (Python, JavaScript) | |
|---|---|---|
| How it converts | Whole program at once | One line at a time |
| When | Before the program runs | While the program runs |
| Result | An .exe (executable) file | No separate file |
| Speed | Fast | Slower |
Easy example: a compiler is like translating a whole book first and then reading it. An interpreter is like translating one line, reading it, then translating the next line.
A short history of C
| Year | What happened |
|---|---|
| 1967 – 1970 | BCPL and then B language were used at Bell Labs. |
| 1972 | Dennis Ritchie made C from B. UNIX was rewritten in C. |
| 1978 | The famous book The C Programming Language by Kernighan and Ritchie ("K&R C"). |
| 1989 / 1990 | First official standard: ANSI C (also called C89 / C90). |
| 1999 – 2024 | Newer versions: C99, C11, C17 and C23. |
Memory trick: B came before C, just like in the alphabet. Full order: BCPL → B → C.
Why learn C today?
- It shows you how a computer really works (memory, data, execution).
- C++, Java, C# and JavaScript look similar to C. Learn C first, and these become easy.
- C is a core subject in B.Tech, BCA, MCA and most computer courses.
Basic Syntax of a C Program
Every C program follows this basic structure:
#include <header_file.h>
int main(void)
{
/* your code goes here */
return 0;
}
| Part | What it does |
|---|---|
#include <header_file.h> | Adds ready-made code. Example: stdio.h gives us printf() to print on the screen. |
int main(void) | The main function. Every C program starts here. |
{ } | Curly braces show where main starts and ends. |
/* … */ | A comment. A note for humans. The computer ignores it. |
return 0; | Ends the program and says "everything went fine". |
Example 1: Hello World Program in C
This is the first program everyone writes. It prints a message on the screen.
#include <stdio.h>
int main(void)
{
printf("Hello, World!\n");
return 0;
}
Output
Hello, World!
Hello World Program Explained Line by Line
#include <stdio.h>: adds the filestdio.h(standard input output). It containsprintf().int main(void): the program starts running from here.{: start ofmain.printf("Hello, World!\n");: prints the text inside the double quotes.\nmeans new line. The semicolon;ends the statement.return 0;: ends the program successfully.}: end ofmain.
How a C Program is Compiled and Run
You write your program in a file called hello.c. The computer cannot run this file directly. It goes through 4 steps:
| Step | Who does it | What happens |
|---|---|---|
| 1. Preprocessing | Preprocessor | Handles lines starting with # (like #include) and removes comments. |
| 2. Compilation | Compiler | Checks for errors and converts the code to assembly code. |
| 3. Assembly | Assembler | Converts assembly code to machine code (object file hello.o). |
| 4. Linking | Linker | Joins your code with library code (like printf) and makes the final .exe file. |
Memory trick: P-C-A-L = "Please Compile And Link". Preprocessing → Compilation → Assembly → Linking.
With the GCC compiler, you need only two commands:
gcc hello.c -o hello (step 1: compile)
./hello (step 2: run on Linux / macOS)
hello.exe (run on Windows)
When you run it, the computer starts from main() and runs each line from top to bottom.
Example 2: C Program to Calculate Total Marks and Percentage
A simple real-life program: add the marks of three subjects and find the percentage.
#include <stdio.h>
int main(void)
{
int maths = 78, physics = 85, chemistry = 69;
int total = maths + physics + chemistry;
float percentage = total / 3.0f;
printf("Total marks: %d out of 300\n", total);
printf("Percentage: %.2f%%\n", percentage);
return 0;
}
Output
Total marks: 232 out of 300 Percentage: 77.33%
Some words here are new (int, float, %d). Don't worry, each one has its own lesson later. For now, just notice that the structure is the same as Example 1: #include, main(), statements ending with ;, and return 0;.
Important Points to Remember
- C was made by Dennis Ritchie at Bell Labs in 1972.
- Every C program has one
main()function. The program starts from there. - Every statement ends with a semicolon
;. - C is case-sensitive:
printfis correct,Printfis wrong. - C files are saved with the .c extension.
Common Mistakes Beginners Make in C
| Mistake | What happens | How to fix |
|---|---|---|
No semicolon: printf("Hi") | Error: expected ';' | Put ; at the end of every statement |
Capital letter: Printf("Hi"); | Error: Printf is not known | Write printf in small letters |
Forgot #include <stdio.h> | Error or warning for printf | Always include the header file |
Single quotes: printf('Hi'); | Error or wrong output | Use double quotes for text: "Hi" |
File saved as hello.txt | Compiler does not accept it | Save the file as hello.c |
Uses and Advantages of C Programming
Where is C used?
- Operating systems: Linux, and parts of Windows and macOS.
- Embedded systems: chips inside washing machines, cars, ACs and routers.
- Databases: SQLite, PostgreSQL and MySQL.
- Other languages: Python itself is written in C.
- Device drivers: software that controls printers, keyboards and other hardware.
Advantages of C
- Fast: C programs run very quickly.
- Portable: the same program can run on different computers.
- Simple: it has only a small number of keywords to learn.
- Strong base: after C, learning C++, Java and data structures is easier.
Limitation: C has no classes or objects (no OOP), and you have to manage memory yourself.
Want to practise right away? See our solved C programs with output.
C Programming Practice Questions
- Why is C called a middle-level language?
- What is the difference between a compiled and an interpreted language?
- Write the 4 steps that turn a C file into a running program.
- What happens if you remove
#include <stdio.h>from Example 1? - What does
\ndo insideprintf()?
Show answers
- Because it is easy to read like a high-level language, and it can also work with memory and hardware like a low-level language.
- A compiled language converts the whole program before it runs. An interpreted language converts one line at a time while it runs.
- Preprocessing → Compilation → Assembly → Linking (P-C-A-L).
- The compiler does not know
printf(), so it shows an error (old compilers show a warning). - It moves to a new line, so the next output starts on the next line.
Coding Exercise
Write a C program that prints your name, course and college on three lines, like this:
Name: Riya Sharma Course: B.Tech Computer Science College: ABC Institute of Technology
Bonus: print a line of * stars above and below.
Show solution
#include <stdio.h>
int main(void)
{
printf("**********************************\n");
printf("Name: Riya Sharma\n");
printf("Course: B.Tech Computer Science\n");
printf("College: ABC Institute of Technology\n");
printf("**********************************\n");
return 0;
}
Quick Quiz: C Programming Basics (MCQ)
-
Who developed the C language?
A) Bjarne Stroustrup B) Dennis Ritchie C) James Gosling D) Guido van Rossum
-
C is a ______ language.
A) markup B) query C) compiled D) interpreted-only
-
A C program starts running from:
A) The first line of the file B)
start()C)main()D)printf() -
Which header file has
printf()?A)
conio.hB)stdio.hC)math.hD)string.h -
What does
return 0;inmain()mean?A) The program failed B) Print 0 on the screen C) The program ended successfully D) Restart the program
Show answers
- B: Dennis Ritchie, at Bell Labs, 1972.
- C: compiled. The whole program is converted before it runs.
- C:
main()is where every C program starts. - B:
stdio.h(standard input output). - C: 0 means the program ended successfully.
Quick Revision for Exams and Interviews
Read this before your exam or interview. The highlighted words are the answer.
Must-remember facts
| Developed by | Dennis Ritchie |
|---|---|
| Where and when | Bell Labs (AT&T), USA, 1972 |
| Made from | B language (BCPL → B → C) |
| First made for | The UNIX operating system |
| Type of language | General-purpose, procedural, compiled, middle-level |
| First standard | ANSI C (C89 / C90). Later: C99, C11, C17, C23 |
| Program starts from | main(); only one per program |
| File extension | .c program file, .h header file |
| 4 steps (P-C-A-L) | Preprocessing → Compilation → Assembly → Linking |
printf() is in | stdio.h |
return 0; means | Program ended successfully |
Frequently asked questions
- Why is C called a middle-level language?
- It is easy to read like a high-level language and can control memory like a low-level language.
- Why is C called the "mother of programming languages"?
- C++, Java, C# and JavaScript are based on C's syntax, and many other languages are written in C.
- Is C compiled or interpreted?
- Compiled. The whole program is converted to machine code before it runs.
- Is C case-sensitive?
- Yes.
printfandPrintfare different. - Can a C program run without
main()? - No. The program starts from
main(). Without it, the linker gives an error. - What does the preprocessor do?
- It handles lines starting with
#and removes comments, before compilation. - What does the linker do?
- It joins your code with library code (like
printf) and makes the .exe file.
Remember
- Every statement ends with
; - Text goes in double quotes
"…";\n= new line. - Include the header file for every library function.
- Compile:
gcc file.c -o file· Run:./file
Next Topic
Next lesson: History and Features of C Language. You will learn where C came from, its versions, and the features that make it fast and portable.