← Back to C Course | Chapter 1: Introduction & Basics | Lesson 1 of 21

C Introduction

C is a small, very fast programming language that sits close to how the computer really works. Many other languages and even operating systems are built with it, like the foundation of a house.

What is C?

C is a general-purpose, procedural programming language built around functions and statements rather than objects.

It gives you fine control over how a program uses memory and the CPU, which is why it still underlies so much of the software you use every day without seeing it.

Example: What is C?

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare total and set it to 0
	int total = 0;
	// Loop: repeat while the condition holds
	for (int i = 1; i <= 5; i++) {
		total += i;
	}
	// Print formatted text to the screen
	printf("Total: %d", total);
	// Return 0 to signal that the program finished successfully
	return 0;
}

Why Learn C?

Learning C forces you to understand what's actually happening under the hood -- how variables occupy memory, how a program is compiled into machine instructions, and how a CPU executes them one at a time.

That mental model carries over directly into languages like C++, Java, and even Python.

Example: Why Learn C?

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare x and set it to 10
	int x = 10;
	// Print formatted text to the screen
	printf("Value: %d, Size in memory: %zu bytes", x, sizeof(x));
	// Return 0 to signal that the program finished successfully
	return 0;
}

How C Works

A C program is first translated by a compiler into an intermediate object file, then linked into a native executable containing raw machine instructions.

Unlike interpreted languages, there's no runtime translating your code as it runs -- the CPU executes your logic directly.

Example: How C Works

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Print formatted text to the screen
	printf("This program runs as compiled machine code, no interpreter needed.");
	// Return 0 to signal that the program finished successfully
	return 0;
}

Applications of C

Operating system kernels (Linux, parts of Windows), database engines like SQLite and PostgreSQL's core, and most other language runtimes are themselves written in C, because it gives predictable performance with almost no hidden overhead.

Example: Applications of C

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Print formatted text to the screen
	printf("C powers OS kernels, database engines, and language runtimes.");
	// Return 0 to signal that the program finished successfully
	return 0;
}

Benefits of C

Because C compiles to native code and lets you manage memory manually with pointers, programs written in it tend to be faster and use less RAM than equivalent code in higher-level languages -- at the cost of you being responsible for that memory yourself.

Example: Benefits of C

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare value and set it to 100
	int value = 100;
	int *ptr = &value;
	// Print formatted text to the screen
	printf("Direct memory control via pointer: %d", *ptr);
	// Return 0 to signal that the program finished successfully
	return 0;
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Assuming C is interpreted like a script, when a C source file must be compiled (for example gcc main.c -o main) before you can run it.
  2. Expecting C to have built-in strings, classes or automatic memory management, when strings are char arrays and memory is your responsibility.
  3. Confusing C with C++ and using cout or class in a .c file, which C compilers reject.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.