Week-1 Basic About Computers
Week-1 Basic About Computers
C Programming - Week 1
C Programming - Week 1
What is a Computer?
How Computers Work?
Central Processing Unit (CPU)
Memory Hierarchy in CPU
What is Programming?
Introduction to C Language
What is a Computer?
A computer is an electronic device that processes data, performs calculations, and executes
instructions to carry out various tasks.
It is a versatile and programmable machine that can perform a wide range of functions, from
simple arithmetic operations to complex data analysis and simulations.
Volatile memory, meaning data is lost when the computer is powered off.
3. Storage Devices:
Examples include hard drives, solid-state drives (SSDs), and external storage devices.
Non-volatile memory, retaining data even when the computer is turned off.
4. Input Devices:
5. Output Devices:
The main circuit board that connects and facilitates communication between all
computer components.
7. Software:
Programs and instructions that tell the computer what tasks to perform.
Input devices such as keyboards, mice, and touchscreens are used to enter data.
2. Processing Stage:
Data and instructions are sent to the Central Processing Unit (CPU).
The CPU decodes instructions and performs calculations and logical operations.
3. Memory Storage:
RAM (Random Access Memory): Temporary storage used for active processes.
Secondary Storage (Hard Drives, SSDs): Long-term storage for files and programs.
4. Control Unit:
It fetches instructions from memory, decodes them, and directs the CPU accordingly.
The ALU performs arithmetic operations (addition, subtraction, multiplication, division) and
logical operations (AND, OR, NOT).
6. Output Stage:
8. Communication:
This allows data exchange over the internet, LANs, and WANs.
9. Software:
Software consists of programs and instructions that tell the computer what to do.
Computers use binary code (0s and 1s) to represent data and instructions.
The CPU (Central Processing Unit) is the primary component of a computer responsible for
executing instructions and performing calculations.
Source: WikiPedia
Key Components:
Controls the flow of data and instructions within the CPU and between other hardware
components.
3. Registers:
Includes the program counter (PC), instruction register (IR), and general-purpose
registers.
Functions:
1. Instruction Execution:
2. Data Processing:
3. Control of Peripherals:
Communicates with input and output devices to manage data transfer.
Accesses and manages data stored in RAM and other memory locations.
Memory hierarchy in a CPU refers to the organization of memory units with varying speeds
and capacities, allowing for efficient data access and processing.
This hierarchy is essential for balancing the trade-offs between speed and capacity in modern
computer systems.
1. Registers:
Purpose:
Registers are the smallest and fastest memory units within the CPU.
Usage:
Examples include the program counter (PC) and general-purpose registers (e.g., AX,
BX, etc.).
2. Cache Memory:
Purpose:
Cache memory serves as a bridge between registers and main memory (RAM).
It provides faster access to frequently used data.
3. Main Memory (RAM - Random Access Memory):
Purpose:
Main memory is the primary memory for program and data storage during active
tasks.
It holds the code and data that the CPU is currently processing.
Characteristics:
Purpose:
Secondary memory provides long-term storage for programs and data, even when
the computer is turned off.
It serves as a large storage pool for files, applications, and the operating system.
Types:
Hard Disk Drives (HDDs): Spinning disks for magnetic data storage.
Solid-State Drives (SSDs): Use flash memory for faster, more durable storage.
Optical Discs (e.g., DVDs, Blu-rays): Used for archiving and software distribution.
USB Drives (Flash Drives): Portable storage for data transfer and backup.
What is Programming?
Programming, also known as coding or software development, is the process of instructing a
computer to perform specific tasks by providing it with a set of structured instructions or
commands in a programming language.
Key Concepts:
1. Programming Languages:
These are formal languages with syntax and semantics used to communicate with
computers.
2. Algorithms:
3. Data Structures:
Data structures are ways to organize and store data efficiently, making it easier to
manipulate and access.
4. Software Development Cycle:
Purpose of Programming:
1. Automation:
2. Problem Solving:
It provides tools to tackle complex problems in various fields, from science and
engineering to finance and entertainment.
3. Creating Software:
4. Innovation:
Programming Process:
3. Writing Code:
Verify that the program works correctly and fix any errors (bugs).
5. Optimization:
6. Documentation:
Document the program's functionality, usage, and code for future reference.
Types of Programming:
1. Application Programming:
Developing software applications like word processors, games, and mobile apps.
2. Web Development:
Creating websites and web applications using languages like HTML, CSS, and JavaScript.
3. Embedded Programming:
Programming embedded systems, found in devices like smartphones, IoT devices, and
car systems.
4. Scientific and Data Analysis Programming:
Using programming to analyze and visualize data in scientific research and data science.
Programming Tools:
2. Text Editors:
Simple tools for writing and editing code, often used by experienced programmers.
Software like Git helps track changes and manage collaborative coding projects.
Introduction to C Language
C is considered as a middle-level language because it supports the feature of both low-level
and high-level languages. C language program is converted into assembly code, it supports
pointer arithmetic (low-level), but it is machine independent (a feature of high-level).
It was developed in the early 1970s by Dennis Ritchie at Bell Labs for system programming
and has since become one of the most widely used programming languages.
Key Characteristics:
1. Procedural Language:
2. Portability:
C code can be compiled and run on various platforms with minor modifications, making
it highly portable.
3. Efficiency:
C provides low-level memory access and efficient control over hardware, making it
suitable for system programming and performance-critical applications.
4. Strongly Typed:
C enforces strong data typing, meaning data types must be explicitly declared and
adhered to.
C comes with a rich standard library that provides functions for I/O, string manipulation,
memory management, and more.
Basic Syntax:
C code is written in a C source file (usually with a .c extension) and follows a structured syntax
with key elements:
Control Structures: Statements for making decisions (if-else), loops (for, while), and
branching.
1 #include <stdio.h>
2
3 int main() {
4 printf("Hello, World!\n");
5 return 0;
6 }
Advantages of C Language:
1. Efficiency: C allows for precise control over hardware, making it efficient for system
programming and resource-constrained applications.
3. Vast Community and Resources: C has a large user community, offering extensive
documentation and libraries.
4. Compatibility: Many other languages, like C++, are based on or compatible with C, extending
its capabilities.
Applications:
3. Compilers and Interpreters: C is used to create compilers and interpreters for other
programming languages.
4. Scientific and Numerical Computing: In fields like engineering and data analysis.