Programming
Python Programming for Beginners
Write your first programs and think like a programmer
Learn the language behind operating systems, step by step
4 sections · 13 lessons · 9h 5m
C is a general-purpose programming language created by Dennis Ritchie at Bell Labs in the early 1970s. It was used to write the UNIX operating system, and today it still powers operating system kernels, embedded devices such as washing machines and routers, databases and compilers for other languages.
C is called a middle-level language: it is readable like a high-level language but also gives you close control over memory, like a low-level language. That is why it is fast, and why learning it teaches you how computers really work.
C is a compiled language. You write source code in a text file ending in .c. A program called a compiler translates it into a machine-code executable that your computer runs directly.
hello.chello.exe on Windows, hello on Linux/macOS)If there is a mistake, the compiler shows an error with the line number, and no executable is created until you fix it.
In this course we use GCC (the GNU Compiler Collection), which is free and works on Windows, Linux and macOS.
If you are on a shared or low-spec computer, start with a free online C compiler. Search for "online C compiler" and pick a well-known one, such as the compilers offered by OnlineGDB, Programiz or similar sites. Type code, click Run, and type any input in the console area. Online compilers are perfect for learning, but avoid pasting private data into them.
Code::Blocks is a free editor (IDE) for C and C++.
hello.c. The .c extension matters.Many programmers prefer Visual Studio Code with a separately installed GCC. On Windows, GCC is commonly installed through MinGW-w64 (for example, via the MSYS2 installer). After installing, add the compiler's bin folder to your system PATH, as described in the installer's documentation. Then check it in Command Prompt:
gcc --version
On Linux, install GCC from your package manager (for example, sudo apt install build-essential on Ubuntu or Debian). On macOS, run xcode-select --install, which installs the Clang compiler; the gcc command works and runs Clang.
Create a file called hello.c:
#include <stdio.h>
int main(void)
{
printf("Namaste! I am learning C.\n");
return 0;
}
Compile and run it from the terminal (Command Prompt, PowerShell or a Linux/macOS terminal), inside the folder where you saved the file:
gcc hello.c -o hello
./hello
On Windows Command Prompt, run hello instead of ./hello. Output:
Namaste! I am learning C.
You will learn what each line means in the next lesson. For now, notice that:
printf prints text, and \n moves to a new line.;.Printf or MAIN will not work.Add -Wall when compiling. It asks GCC to warn you about suspicious code, which catches many beginner bugs early:
gcc -Wall hello.c -o hello
Some older books use Turbo C, with #include <conio.h>, clrscr() and void main(). These are not part of standard C and do not work on modern compilers. This course uses standard C with int main(void), which works everywhere.
printf statements.Let us look closely at a slightly bigger program:
/* greet.c: asks for an age and prints a message */
#include <stdio.h>
int main(void)
{
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You are %d years old.\n", age);
printf("In 5 years you will be %d.\n", age + 5);
return 0;
}
Sample run (the user types 19):
Enter your age: 19
You are 19 years old.
In 5 years you will be 24.
Line by line:
/* ... */ is a comment. The compiler ignores it. Single-line comments start with //.#include <stdio.h> is a preprocessor directive. It includes the standard input/output header, which declares printf and scanf.int main(void) is the main function. Every C program starts running here. int means it returns a whole number to the operating system.{ } mark the start and end of the function body.int age; declares a variable called age that holds an integer.return 0; ends main and tells the operating system the program finished successfully.printf prints a format string. Inside it, format specifiers starting with % are replaced by the values that follow.
#include <stdio.h>
int main(void)
{
int marks = 87;
float percent = 72.5f;
char grade = 'B';
printf("Marks: %d\n", marks);
printf("Percent: %.1f%%\n", percent);
printf("Grade: %c\n", grade);
printf("Name: %s\n", "Kavya");
return 0;
}
Output:
Marks: 87
Percent: 72.5%
Grade: B
Name: Kavya
| Specifier | Type |
|---|---|
%d | int (whole number) |
%f | float or double (decimal); %.2f shows 2 decimal places |
%c | char (single character) |
%s | string (text) |
%% | prints a percent sign |
| Sequence | Meaning |
|---|---|
\n | New line |
\t | Tab |
\" | Double quote inside a string |
\\ | Backslash |
scanf reads values typed by the user. It uses the same specifiers, but for float you use %f and for double you use %lf.
#include <stdio.h>
int main(void)
{
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
printf("Sum = %d\n", a + b);
return 0;
}
If the user types 12 30, the output is Sum = 42.
&a means "the memory address of a". scanf needs to know where to store the value, so you pass the address. Forgetting the & is one of the most common beginner mistakes: the program may crash or print garbage. (Strings are an exception, which you will see later.)
When reading a char after a number, put a space before %c, like scanf(" %c", &ch);. The space skips the leftover Enter key in the input.
C does not care about spaces and new lines, but people do. Indent the code inside braces by four spaces, put one statement per line, and use meaningful names like total_marks instead of x. Your code will be easier to read and debug.
%d to print a float, or %f to print an int. The output will be wrong. Compile with -Wall and GCC warns you.& in scanf.#include <stdio.h> with a typo, so printf is "implicitly declared".float and %f) and prints it with exactly two decimal places using %.2f.\t to line up the columns: item name, quantity and price.& from one scanf, compile with -Wall, and read the warning GCC gives.C is one of the oldest and most influential programming languages still in wide use. Operating systems, embedded devices, databases and parts of many other languages are written in C. Learning it teaches you how a computer really stores data in memory, which makes every language you learn afterwards easier. C is also part of many school, polytechnic, BCA, B.Tech and diploma syllabi, and often appears in technical interviews and entrance tests.
Every lesson has complete, working programs that you can copy, compile and run, followed by a practice task. You will use a free compiler such as GCC (through Code::Blocks or MinGW-w64 on Windows) or a free online C compiler in your browser, so a basic laptop or even a cyber café computer is enough.
A simple calculator, a times-table printer, a marks analyser using arrays, string utilities, a student record program using structures, and a mini project that saves records to a file.
C can be strict and its error messages can look scary. The course shows the most common beginner mistakes, such as a missing semicolon, a forgotten & in scanf, array index errors and uninitialised variables, and how to fix them.
Pass the final online exam (20 minutes, 15 questions, pass mark 40%) to receive your certificate instantly. Each certificate has a unique number and QR code for instant verification.
This is an independent, institute-issued skill-training certificate — not a government-recognised degree or diploma.
Muninder Singh
Leave your details and our team will get back to you, usually within one working day.
Programming
Write your first programs and think like a programmer
Programming
Build and publish your first responsive website
Programming
Track your code, work with others and publish your projects
Free
Includes certificate