C Programming Basics and Concepts

Sep 28, 2024

C Programming Unit 1 Lecture Notes

Introduction

  • Overview of C Programming unit.
  • Link to C language tutorials and study materials available in the description.
  • Topics covered include:
    • Components of a computer
    • Computer languages and translators
    • Memory types
    • Operating systems

Components of a Computer

  • Definition of Computer: An electronic device that takes input, processes it, and provides output.
    • Example: Input via keyboard, output via monitor.

Categories of Computer Components

  1. Hardware: Physical parts of a computer (e.g., CPU, monitor, mouse, keyboard).
  2. Software: Instructions for the computer.
    • Types of Software:
      • System Software: Designed for system management (e.g., Windows, Linux).
      • Application Software: Designed for user tasks (e.g., MS Office, Photoshop).

Basic Operations of a Computer

  1. Input: Entering data.
  2. Storage: Saving data (RAM, hard disk).
  3. Processing: Performing operations on data.
  4. Output: Displaying results.
  5. Control: Managing the sequence of operations.

Types of Memory

  1. Primary Memory: Temporary storage.
    • RAM (Random Access Memory):
      • Static RAM (SRAM): Retains data until powered off.
      • Dynamic RAM (DRAM): Loses data quickly if not refreshed.
    • ROM (Read-Only Memory): Permanent storage.
      • Types: PROM, EPROM, EEPROM.
  2. Secondary Memory: External storage (e.g., CDs, DVDs, USB drives).

Computer Languages

  • Types:
    1. Machine Level Language: Binary code (0s and 1s).
    2. Assembly Language: Uses symbols.
    3. High-Level Language: Human-readable languages (e.g., C).

Translators

  • Converts high-level language to machine language.
    • Compiler: Converts the whole program at once.
    • Interpreter: Converts line by line.

Operating Systems

  • Interface between users and hardware.
  • Examples: Windows, Linux.
  • Functions:
    • Memory management
    • Process management
    • Device management
    • File management
    • Security control

Types of Operating Systems

  1. Batch Operating System: Processes jobs in groups.
  2. Multitasking/Time Sharing OS: Multiple users access a computer simultaneously.
  3. Real-Time OS: Responds immediately to inputs (e.g., military applications).
  4. Mobile OS: Designed for mobile devices (e.g., Android, iOS).
  5. Network OS: Manages network resources on a server.
  6. Distributed OS: Operates across multiple processors.

Numbering Systems in C Programming

  • Types:
    1. Binary: Base 2.
    2. Octal: Base 8.
    3. Decimal: Base 10.
    4. Hexadecimal: Base 16.

Introduction to C Programming

  • Developed by Dennis Ritchie in 1972.
  • C is a case-sensitive, robust, middle-level programming language.

Structure of a C Program

  • Header files: (e.g., #include <stdio.h>)
  • Main function: int main() {}

Data Types & Variables

  • Data Types:
    • Primary: int, char, float.
    • Variables: Store data values.

Operators in C

  • Types of Operators:
    1. Arithmetic Operators: +, -, *, /, %.
    2. Relational Operators: ==, !=, >, <.
    3. Logical Operators: && (AND), || (OR), ! (NOT).
    4. Bitwise Operators: &, |, ^, ~.
    5. Assignment Operators: =, +=, -=, *=, /=.
    6. Increment/Decrement Operators: ++, --.

Control Structures

  1. Conditional Statements: if, if-else, else if, switch.
  2. Loops: for, while, do-while.

Storage Classes

  • Types:
    1. Auto: Local variable, exists in the block.
    2. Static: Local variable that retains value after scope ends.
    3. Extern: Global variable accessible across files.
    4. Register: Stores in CPU register for fast access.

Type Conversion

  • Implicit Conversion: System converts smaller types to larger (e.g., int to float).
  • Explicit Conversion: User manually converts (e.g., float to int).

Command Line Arguments

  • Arguments passed to the program via command prompt.
  • int main(int argc, char *argv[]) handles command line arguments.

Example Programs

  • Check even or odd number.
  • Print tables using goto statement.

Conclusion

  • Comprehensive understanding of C programming basics, components, memory types, programming languages, and operators.