An overview of what programming is, its importance, different programming languages, and the basic concepts involved in programming.
Introduction to Programming – Quick Reference Notes
| Concept | Description | Typical Example |
|---|---|---|
| Algorithm | Step‑by‑step procedure to solve a problem. | Sorting a list of numbers. |
| Syntax | Formal rules that define how code must be written. | if (x > 0) { … } in C‑style languages. |
| Semantics | Meaning of syntactically correct statements. | x = x + 1 increments x. |
| Variable | Named storage location for data that can change. | int count = 0; |
| Data Type | Classification of values (e.g., integer, string, boolean). | float, char, bool. |
| Control Flow | Structures that dictate the order of execution. | if/else, for, while. |
| Function / Procedure | Reusable block of code that performs a specific task. | def add(a, b): return a + b |
| Library / API | Pre‑written code that provides additional functionality. | math.sqrt(), java.util.ArrayList. |
| Debugging | Finding and fixing errors (bugs) in code. | Using breakpoints, print statements. |
| Compilation / Interpretation | Translating source code to executable form. | gcc (compile), Python REPL (interpret). |
| Paradigm | Key Idea | Typical Languages |
|---|---|---|
| Procedural | Code organized as a sequence of instructions and procedures. | C, Pascal |
| Object‑Oriented (OO) | Data and behavior are bundled into objects; emphasizes inheritance & polymorphism. | Java, Python, C++ |
| Functional | Computation expressed as evaluation of pure functions; avoids mutable state. | Haskell, Lisp, Scala |
| Declarative | Describe what should be done, not how; includes SQL, HTML, Prolog. | |
| Event‑Driven | Flow controlled by events (user actions, messages). | JavaScript (browser), C# (GUI) |
# 1. Import modules (libraries)
import math
# 2. Define constants
PI = math.pi
# 3. Define functions
def area_of_circle(radius):
"""Return the area of a circle given its radius."""
return PI * radius ** 2
# 4. Main execution block
if __name__ == "__main__":
r = float(input("Enter radius: "))
print(f"Area = {area_of_circle(r):.2f}")
Typical sections