💡 Introduction to Programming — What It Is & How Computers Run Code
Learn what programming is, how source code becomes machine code, and the difference between compiled and interpreted languages. Beginner-friendly intro with examples and interview Q&A.
Programming is writing precise instructions for a computer to follow. A computer is fast but dumb — it only does exactly what you tell it, one step at a time.
🧠 How code becomes something a computer runs
You write source code in a language like C++. A compiler translates it into machine code (1s and 0s the CPU understands). The compiled file is the program you run.
// source code (C++)
#include <iostream>
int main() {
std::cout << "Hello, world!";
return 0;
}⚡ Compiled vs interpreted
- Compiled (C, C++, Rust, Go) — fully translated to machine code once, then run directly. Fast.
- Interpreted (Python, JavaScript, Ruby) — read and executed line-by-line by a runtime. More flexible, slightly slower.
- Hybrid (Java, C#) — compiled to an intermediate bytecode, then JIT-compiled at runtime.
💡 Why C++ for fundamentals?
C++ exposes everything: memory, types, the call stack, pointers. Once you understand it, every other language feels familiar.
💻 Code Examples
Your first C++ program
#include <iostream>
int main() {
std::cout << "Hello, world!";
return 0;
}Output:
Hello, world!
A program that does math
#include <iostream>
int main() {
int a = 5, b = 3;
std::cout << a + b;
return 0;
}Output:
8
⚠️ Common Mistakes
- Forgetting that the compiler must succeed BEFORE you can run the program — compile errors stop you cold.
- Confusing source code (what you write) with the compiled binary (what runs).
- Thinking 'high-level' languages are 'better' — each language is a tool for a different job.
🎯 Interview Questions
Real questions asked at top product and service-based companies.
Q1.What is a programming language?Beginner
A formal system for giving instructions to a computer. Languages range from low-level (assembly, close to the CPU) to high-level (Python, abstracted from hardware). Each has a syntax and semantics the compiler/interpreter understands.
Q2.What's the difference between a compiler and an interpreter?Beginner
A compiler translates source code to machine code ahead of time, producing a standalone executable. An interpreter reads and executes the source code line-by-line at runtime, no separate executable produced.
Q3.What is an algorithm?Beginner
A finite, ordered set of steps to solve a problem or compute a result. A program is an algorithm expressed in a programming language.
Q4.Why is C++ popular for systems programming?Intermediate
It gives direct control over memory and hardware, generates efficient machine code, and supports both low-level operations (pointers, bit manipulation) and high-level abstractions (OOP, templates, STL).
Q5.What does `int main()` mean in C++?Beginner
It's the entry point of a C++ program. The OS calls main when the program starts. `int` is the return type — a value returned to the OS indicating success (0) or an error code.
🧠 Quick Summary
- Programming = writing exact instructions for a computer.
- Source code → compiler → machine code → executable.
- Compiled (C++, Rust) is fast; interpreted (Python, JS) is flexible.
- C++ exposes memory and types — perfect for fundamentals.
- Every C++ program starts execution in `int main()`.