Knowlet

Unit I: Introduction to Programming


1. Computer Programs & Languages

A Computer Program is a precise set of instructions given to a computer to perform a specific task.

  • Natural Language: Languages used by humans for communication (like English or Hindi), which are often ambiguous and flexible.
  • Programming Language: A formal language with strict rules (syntax) used to communicate instructions to a computer.

2. Levels of Programming Languages

Programming languages are categorized based on their distance from the computer hardware.

  • Machine Level Language: The lowest level, consisting of binary code (0s and 1s) that the CPU executes directly.
  • Assembly Level Language: Uses mnemonic codes (like ADD, SUB) instead of binary, requiring an Assembler for translation.
  • High-level Programming Language: Human-readable languages (like C, Python) that are independent of the computer's hardware architecture.

3. Compiler and Interpreter

High-level code must be translated into machine code for execution.

Feature Compiler Interpreter
Translation Translates the entire program at once. Translates the program line-by-line.
Execution Speed Faster, as translation is done before running. Slower, as translation happens during execution.
Error Reporting Lists all errors after scanning the whole file. Stops execution at the first error found.

4. Core Programming Terms

Essential terminology used in software development:

  • Source Code: The original code written by the programmer in a high-level language.
  • Target Code: The output produced by the compiler, usually machine code.
  • Compiling: The process of converting source code into machine code.
  • Warning: A message from the compiler about potential issues that don't stop the program from running but might cause bugs.
  • Debugging: The process of finding and fixing errors in the code.
  • Testing: Verifying the program's output against expected results to ensure correctness.

5. Errors in Computer Programs

Errors, or "bugs," prevent a program from working correctly.

Types of Errors:

  • Syntax Errors: Violations of the language's grammar rules (e.g., a missing semicolon). The compiler will catch these.
  • Logical Errors: The program runs but gives the wrong result because the underlying logic is flawed.
  • Runtime Errors: Errors that occur while the program is running, such as dividing by zero or running out of memory.

Exam Tips

  • Compiler vs. Interpreter: This is a high-frequency question. Focus on the "line-by-line" vs. "whole program" distinction.
  • Source Code: Remember that source code is human-readable, whereas target code is computer-readable.
  • Debugging vs. Testing: Debugging is fixing a known issue; testing is looking for issues.

Frequently Asked Questions

Q: Why do we need High-level languages if the computer only understands binary?
High-level languages are easier for humans to write, read, and maintain. Compilers take care of the translation into machine code.

Q: Does a warning stop my program from running?
No, a program can still run with warnings, unlike errors which prevent compilation. However, it is best practice to fix warnings to avoid unpredictable behavior.

Did this resource help you study?

Share feedback or report issues to help improve this resource.