⚡0 XP🔥0

Introduction to C

Lesson 1 of 13 ⏱ 4 min read ✎ 2 exercises ❓ 5-question quiz ▶ Runs C

What C is, why it is still used everywhere, how a C program is compiled and run, and the structure of your first program.

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#

▶ Try it YourselfC
Ctrl + Enter to run
Output
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.
Common Mistake

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:

  1. Preprocessor - handles lines starting with # (copies header files, replaces macros).
  2. Compiler - checks your syntax and translates C into assembly code.
  3. Assembler - converts assembly into machine code (an object file, hello.o).
  4. Linker - joins your object file with library code (like the real printf) to make the final program (hello.exe on Windows, a.out or hello on Linux).
hello.c  →  [preprocessor]  →  [compiler]  →  [assembler]  →  hello.o  →  [linker]  →  hello.exe
Did you know?

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)
▶ Try it YourselfC
Ctrl + Enter to run
Output
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 */
▶ Try it YourselfC
Ctrl + Enter to run
Output
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 --install in Terminal to get clang/gcc.

Compile and run from a terminal:

gcc hello.c -o hello     # compile
./hello                  # run (on Windows: hello.exe)
Tip

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 you printf and scanf.
  • \n prints a new line; \t a tab; comments use // or /* */.

Practice Exercises

Write your code, then press Check. Your program is tested automatically.

1

Hello, Vindhyaedu

Write a program that prints exactly Hello, Vindhyaedu! on one line.

Expected output:
Hello, Vindhyaedu!
2

Three lines

Print this address card using three printf calls:

Vindhyaedu Training Institute
Indore, Madhya Pradesh
Learn. Code. Grow.
Expected output:
Vindhyaedu Training Institute
Indore, Madhya Pradesh
Learn. Code. Grow.

Quick Quiz

Q1.

Who created the C language, and where?

Q2.

What does #include <stdio.h> do?

Q3.

Which stage turns your .c file into machine code?

Q4.

What does return 0; at the end of main mean?

Q5.

Every C statement ends with...