Unit 1: Introduction to Programming

Table of Contents

1. Introduction to Computer Programs

A computer program is a sequence of instructions, written in a specific programming language, that a computer can execute to perform a task. Think of it as a detailed recipe that a computer follows precisely.

2. Programming Languages

Natural Language vs. Programming Language

Natural Languages (like English, Hindi, Bengali) are what humans use to communicate. They are complex, ambiguous, and evolve over time.

Programming Languages (like C, Java, Python) are formal, structured languages used to communicate instructions to a computer. They are unambiguous and have strict syntax rules.

Machine Level Language (1st Generation)

Assembly Level Language (2nd Generation)

High-level Language (3rd Generation)

3. Language Translators

Computers only understand machine code. A translator is a program that converts high-level or assembly language into machine code.

Compiler

A compiler reads the *entire* source code at once, translates it, and creates a separate executable file (e.g., an .exe file).

Interpreter

An interpreter reads the source code one line at a time, translates that line, and executes it immediately.

4. Key Programming Terms

5. Errors in Computer Programs

There are three main types of errors in programming:

  1. Syntax Errors (Compile-time Errors):
    • Errors in the grammar of the programming language.
    • Examples: Forgetting a semicolon (;), misspelling a keyword (whlie instead of while).
    • These are caught by the compiler, and the program will not run.
  2. Runtime Errors:
    • Errors that occur *while* the program is running.
    • Examples: Dividing a number by zero, trying to access an invalid memory location.
    • These errors will cause the program to crash or behave unexpectedly.
  3. Logical Errors:
    • The program runs successfully but produces the wrong output.
    • The "grammar" is correct, but the "meaning" (logic) is flawed.
    • Example: Using (a + b) / 2 to calculate the average but writing a + b / 2 (which is a + (b/2)).
    • These are the most difficult errors to find and fix.