Introduction to Computer Languages, C, and Flowcharts

Computer Languages

  • Machine Level Language:

    • Lowest-level language composed of binary digits (00 and 11) directly executed by the CPU.

    • Advantages: Very fast execution with no translation required, direct control over hardware, memory efficient.

    • Disadvantages: Difficult to read and write, machine-dependent, error-prone.

  • Assembly Level Language:

    • Uses mnemonic abbreviations (e.g., MOV, ADD, JMP) to represent machine instructions.

    • Requires an Assembler to translate code into machine code.

    • Advantages: Easier to read and write than machine code, mnemonics are easy to remember.

    • Disadvantages: Machine-dependent, complex compared to high-level languages.

  • High-Level Languages:

    • Close to human language; includes control structures, I/O facilities, and built-in functions (e.g., FORTRAN, COBOL, PASCAL, C, C++, Java, Python).

    • Advantages: Machine-independent (portable), easier to learn, faster development time.

    • Disadvantages: Slower execution, requires a compiler or interpreter, provides less direct hardware control.

Introduction to C Language

  • Origin: Developed by Dennis Ritchie at Bell Laboratories in 1972 to construct the UNIX operating system.

  • Key Features: High-speed execution, highly versatile, foundational syntax shared with Java, Python, C++, and C#.

  • C vs. C++: C++ extends C by adding support for classes and objects, which C lacks.

C Header Files

  • Purpose: Files carrying a .h extension that contain forward declarations of functions, data types, and macros without definitions, adhering to the One Definition Rule.

  • Categories:

    • User-Defined: Created by developers and located in the working directory.

    • Standard Library: Located in system directories (e.g., stdio.h).

  • Syntax: Included using the #include <header-file-name.h> preprocessor directive.

Program Code Types

  • Source Code: Human-readable high-level or assembly code created by developers; easily alterable.

  • Object Code: Low-level machine code in binary format generated by a compiler or translator; executable by the CPU and non-modifiable.

  • Executable Code: Compiled and linked machine-level instructions loaded into main memory (RAM) for execution.

Source Code vs Object Code

Algorithms

  • Definition: A finite, well-defined sequence of steps designed to perform a computation or solve a specific problem.

  • Properties: Precisely defined inputs/outputs, clear and unambiguous steps, language-independent.

  • Addition Algorithm Example:

    1. Start

    2. Declare variables num1, num2, and sum

    3. Read num1 and num2

    4. Calculate sum→num1+num2\text{sum} \rightarrow \text{num1} + \text{num2}

    5. Display sum

    6. Stop

Flowcharts

  • Definition: Visual representations of an algorithm using standard visual shapes and directional arrows.

  • Standard Symbols:

    • Terminal/Terminator (Oval): Represents Start, Stop, or Halt in execution flow.

    • Input/Output (Parallelogram): Represents input reading or output display operations.

    • Action/Process (Rectangle): Represents arithmetic operations and general data processing.

    • Decision (Diamond): Represents conditional branching (e.g., True/False, Yes/No).

    • On-Page Connector (Circle): Connects distinct flowchart sections on the same page.

    • Flow Lines (Arrows): Direct the sequence of execution flow.

Flowchart Example for Finding the Greater of Two Numbers