What is C?#
C is a general-purpose programming language created by Dennis Ritchie at Bell Labs in 1972. It was built to write the UNIX operating system, and today it still runs the world underneath you:
- Operating systems - the Linux, Windows and macOS kernels are mostly C.
- Embedded systems - washing machines, car engines, routers, medical devices, Arduino boards.
- Databases and tools - MySQL, SQLite, Git, the Python interpreter itself.
- Placement exams - C is the first language in most B.Tech/BCA/MCA courses and a favourite for interview questions.
C is called a middle-level language: it is readable like a high-level language, but it lets you work directly with memory addresses like a low-level language. That is why it is fast, and also why it teaches you how computers really work.
C एक compiled भाषा है - आपका लिखा हुआ code पहले compiler द्वारा machine code में बदला जाता है, फिर चलता है। Python की तरह line-by-line नहीं चलता। इसी वजह से C बहुत तेज़ है और Operating System, embedded devices जैसी जगहों पर इस्तेमाल होती है।
Your first C program#
Hello, World!
Press Run. The code is sent to a real GCC compiler, compiled and executed, and the output comes back to you.
Line by line#
| Line | Meaning |
|---|---|
#include <stdio.h> |
A preprocessor directive. It includes the standard input-output header, which declares printf and scanf. |
int main() |
Every C program starts running from the main function. int means it returns a whole number to the operating system. |
{ ... } |
Curly braces mark the body (block) of the function. |
printf("Hello, World!\n"); |
Prints text. \n is the newline character - it moves the cursor to the next line. |
return 0; |
Ends main and reports "success" (0) to the operating system. |
Every statement ends with a semicolon ;. Forgetting it gives an error like expected ';' before 'return'. The compiler usually points to the line after the real mistake.
How a C program becomes an executable#
When you compile hello.c, four tools run one after another:
- Preprocessor - handles lines starting with
#(copies header files, replaces macros). - Compiler - checks your syntax and translates C into assembly code.
- Assembler - converts assembly into machine code (an object file,
hello.o). - Linker - joins your object file with library code (like the real
printf) to make the final program (hello.exeon Windows,a.outorhelloon Linux).
hello.c → [preprocessor] → [compiler] → [assembler] → hello.o → [linker] → hello.exe
This is why C needs a compile step before it can run, while Python does not. The good news: the compiled program runs very fast and needs no C installed on the computer that runs it.
Escape sequences#
Inside a string, a backslash \ starts a special character:
| Sequence | Meaning |
|---|---|
\n |
new line |
\t |
tab (jump to the next tab stop) |
\\ |
a backslash |
\" |
a double quote inside a string |
\a |
beep (alert) |
Name: Asha City: Indore She said "C is fast!" Path: C:\Users\asha
Comments#
Comments are notes for humans. The compiler ignores them.
// single-line comment
/* multi-line comment
can span many lines */
Comments are ignored by the compiler.
Installing C on your computer#
You can do every lesson here in the browser, but for projects install a compiler:
- Windows - install Code::Blocks (with MinGW) for an all-in-one IDE, or VS Code + the MinGW-w64 GCC compiler.
- Linux - GCC is usually there already. If not:
sudo apt install build-essential. - macOS - run
xcode-select --installin Terminal to getclang/gcc.
Compile and run from a terminal:
gcc hello.c -o hello # compile
./hello # run (on Windows: hello.exe)
Add -Wall to see all warnings: gcc -Wall hello.c -o hello. Warnings often point to real bugs before they happen.
Summary#
- C is a fast, compiled, middle-level language used for OSes, embedded systems and tools.
- A program starts at
main(); statements end with;; blocks use{ }. #include <stdio.h>gives youprintfandscanf.\nprints a new line;\ta tab; comments use//or/* */.