0% found this document useful (0 votes)
10 views35 pages

Overview of Computer Generations and Basics

Uploaded by

rakesh.veeranki
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views35 pages

Overview of Computer Generations and Basics

Uploaded by

rakesh.veeranki
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Unit-1

1. Introduction to Programming and problem solving:

History of computers, Basic organization of computer: ALU, Input-Output units, memory,


program counter, Introduction to Program Languages, Basics of computer program
Algorithms, Flowchart, Pseudo code, Introduction to Compilation and execution, Primitive
data types, variables and Constants, Basic Input and output, Operations, Type conversion
and casting.

1. History of computers or Generations of Computers

“Very Tall Intelligent Men Act”

Definition & Concept

 Evolution of computers divided into five generations (based on technology of switching


devices & processing power).
 Each generation = smaller size, faster speed, higher efficiency, and reduced cost.

Short code for Remembering of the Years


1940-56, 56-63, 64-71, 71-Present, Future
Difference of the year’s 16- 7- 7- present- Present and beyond

1. First Generation (1940–1956) – Vacuum Tubes

 Technology: Vacuum tubes for calculation, storage & control.


 Examples: ENIAC, EDVAC, UNIVAC-1.
 Characteristics:
o Very bulky, required huge rooms.
o Generated large heat → required air-conditioning.
o Very high electricity consumption.
o Programming in machine & assembly language.
o Used punched cards & paper tapes.
 Drawbacks: Large size, expensive, slow speed, frequent failures.

2. Second Generation (1956–1963) – Transistors

 Technology: Transistors (replaced vacuum tubes) + magnetic core memory.


 Examples: IBM 1400, IBM 1620, IBM 7090, CDC 3600.
 Characteristics:
o Smaller, faster, more reliable, less heat.
o Introduction of CPU, memory, I/O units.
o Programming in assembly language & high-level languages (FORTRAN,
ALGOL, and COBOL).
 Advantage: Low cost, less power consumption.
 Drawback: Still generated heat, limited storage.

3. Third Generation (1964–1971) – Integrated Circuits (ICs)

 Technology: ICs (chips with multiple transistors).


 Examples: IBM 360, IBM 370, NCR 395, B6500.
 Characteristics:
o Smaller, cheaper, high processing speed.
o Microelectronics introduced.
o Memory shifted to solid state devices.
o Arithmetic/logical operations in microseconds.
o Higher-level languages like BASIC introduced.
o Development of minicomputers.
 Advantage: Reliability & performance improved greatly.

4. Fourth Generation (1971–Present) – Microprocessors

 Technology: Microprocessor (LSI → VLSI circuits).


 Examples: Intel 4004, Apple II, Altair 880.
 Characteristics:
o Entire CPU on a single chip.
o Personal computers (PCs) introduced.
o Concepts of multiprocessing, multiprogramming, time-sharing.
o Faster, smaller, portable → PCs & laptops.
o Computer networks & internet developed.
 Advantage: Low cost, high speed, widespread use.

5. Fifth Generation (Present & Beyond) – Artificial Intelligence

 Technology: AI-based, parallel processing, VLSI & ULSI.


 Examples/Applications: Expert systems, Neural Networks, Robotics, Voice
Recognition, Natural Language Processing.
 Languages: LISP, Prolog (AI programming).
 Characteristics:
o Intelligent decision-making ability.
o Ability to understand natural language.
o Extremely fast processing.
o Focus on parallelism & advanced AI research.
 Future Scope: Image recognition, human-like thinking, smart assistants.
Summary of five generations

Generation Technology Speed Size Language Examples


1st Vacuum Tubes Milliseconds Very Machine/Assembly ENIAC,
Large UNIVAC
2nd Transistors Microseconds Smaller FORTRAN, IBM 1400,
COBOL PDP-8
3rd ICs Nanoseconds Mini BASIC IBM 360,
NCR 395
4th Microprocessors Picoseconds Micro/PC C, C++ Intel 4004,
Apple II
5th AI, VLSI/ULSI Extremely Very LISP, Prolog AI Robots,
High Small Neural
Networks

1.1 What is a computer?

Computer is an advanced electronic device that takes raw data as an input from the user and
processes it under the control of a set of instructions (called program), produces a
result(output), and saves it for future use. .

Functionalities of a Computer

There are three basic functionalities of a Computer System and they are

 Input
 Process
 Output

But if we look at it in a very broad sense, any digital computer carries out the following five
functions:

Step 1 - Takes data as input.

Step 2 - Stores the data/instructions in its memory and uses them as required.

Step 3 - Processes the data and converts it into useful information.

Step 4 - Generates the output.

Step 5 - Controls all the above four steps.

1.2. Basic Organization of Computer

A computer follows the Input–Process–Output cycle. The main components of a computer are
the Input Unit, Central Processing Unit (CPU), Memory Unit, and Output Unit.
The Input Unit accepts data and instructions from the user in human-readable form and converts
them into machine-readable form. Devices such as keyboards, mice, and scanners act as input
units.

The Central Processing Unit (CPU) is the brain of the computer. It consists of three main parts:
the Arithmetic Logic Unit (ALU), the Control Unit (CU), and a set of registers including the
Program Counter (PC).

The ALU performs arithmetic and logical operations, the CU controls and coordinates the
activities of all units, and the PC keeps track of the next instruction to be executed.

The Memory Unit stores data and instructions. It acts as a bridge between the CPU and
input/output devices.

The Output Unit converts processed results into human-readable form using devices like
monitors, printers, and speakers. Thus, the organization of a computer is like a well-structured
system in which each unit has a defined role in performing the overall task of processing
information.

Basic Organization of Computer

Von Neumann Architecture


Mathematician John Von Neumann conceived a computer architecture which forms the core of
nearly every computer system in use today. This architecture is known as Von Neumann
architecture. It is a design model for the modern computers which has central processing unit
(CPU) and the concept of memory used for storing both data and instructions. This model
implements the stored program concept in which the data and the instructions both are stored in
the memory. All computers share the same basic architecture which have memory, an I/O
system, arithmetic logic unit (ALU) and control unit (CU)
Von Neumann Architecture

1.2.1. Arithmetic Logic Unit (ALU)

The Arithmetic Logic Unit is a key part of the CPU, An arithmetic logic unit (ALU) is a digital
circuit used to perform arithmetic and logic operations. That performs all the arithmetic and
logical operations. Arithmetic operations include addition, subtraction, multiplication, and
division. Logical operations include comparisons such as less than (<), greater than (>), equal to
(=), AND, OR, and NOT. It represents the fundamental building block of the central processing
unit (CPU) of a computer.

For example, if a user enters the operation 10 + 5, the ALU takes these values from registers,
performs the addition, and then stores the result in memory or sends it to the output unit.
Similarly, for a comparison like A > B, the ALU checks the condition and returns true or false.
The ALU works under the supervision of the Control Unit, which sends control signals to
indicate which operation has to be performed. Therefore, the ALU acts as the calculator of the
computer system.

1.2.2. Input and Output Units

The Input Unit is responsible for accepting data and instructions from the user. Since computers
understand only binary (0s and 1s), the input devices convert human-readable data into binary
form. Examples of input devices include the keyboard, mouse, scanner, microphone, and camera.
The Output Unit presents the processed results to the user in a readable form. It converts
machine-readable binary data into human-readable form. Examples include monitors, printers,
and speakers.

For example, when we type on the keyboard, the characters are converted into binary code and
then displayed as letters on the monitor. Thus, the input-output system acts as a communication
bridge between the user and the computer system.
1.2.3. Memory Unit

The memory unit of a computer is used to store data, instructions, and intermediate results. It is
classified into primary memory and secondary memory
memory.

Primary memory is directly accessible by the CPU. It is faster but smaller in size. It holds the
data and instructions that the processor is currently working on. It includes Random Access
Memory (RAM), which is volatile memory and loses data when power is off. It also includes
Read Only Memory (ROM), which is non non-volatile
volatile and stores permanent programs like the BIOS.

Cache Memory is a very high high-speed


speed memory located between CPU and RAM, storing
frequently used instructions.

Registers are the smallest and fastest type of memory inside the CPU, used to hold temporary
data and addresses. The Program Counter is also a special register that stores the address of the
next instruction.

Secondary memory is used for permanent storage of data. It is slower than primary memory but
has very large capacity. The contents of the secondary memory first get transferred to the
primary memory and then are accessed by the processor; this is because the processor does not
directly interact with the secondary memory.

Examples include Hard Disk Drives (HDD), Solid State Drives (SSD), DVDs, and USB drives.

The memory hierarchy can be visualized as a pyramid where the top levels (registers and cache)
are very fast but small and costly, while the lower levels (RAM, hard ddisk,
isk, external devices) are
larger but slower. Thus, memory in a computer acts like the human brain—it brain remembers
instructions and data both temporarily and permanently depending on the type of memory used.

Memory hierarchy diagram


1.2.4 Program Counter (PC)

The Program Counter is a special-purpose register inside the CPU. It keeps track of the address
of the next instruction to be executed. After fetching an instruction from memory, the Program
Counter automatically updates to point to the next instruction. For example, if a program has
instructions stored at addresses 100, 104, and 108, then initially the Program Counter will point
to 100. Once the instruction at address 100 is executed, the PC updates to 104, and then to 108.
Thus, the Program Counter ensures the sequential execution of instructions unless a jump or
branch instruction changes the normal sequence. Without the Program Counter, the CPU would
not know which instruction to execute next.

1.3 Computer software is a collection of computer programs and related data that provides the
instructions for a computer what to do and how to do it. Software refers to one or more computer
programs and data held in the storage of the computer for some purpose.

Basically computer software is of three main types

System Software:

System software is the software that controls and manages the hardware of a computer. It allows
different hardware parts (like keyboard, monitor, printer, and CPU) to work together. The main
purpose of system software is to make the computer easy to use by hiding the complex details of
the hardware from the user. It also manages the resources of the computer such as memory,
processor time, and input/output devices in a safe and proper way.

Examples of System Software:

 Device Drivers – Programs that control hardware devices like printers, keyboards, or
graphics cards.
 Operating Systems – Such as Windows, Linux, or mac OS.
 Utilities – Programs that help in system maintenance, like antivirus or file management
tools.
 Servers – Special software that provides services to other computers.
 Window Systems – Software that manages graphical interfaces.
Programming Software:
Programming software is the software used by programmers to create, test, and debug other
programs. It provides tools that make the process of writing programs easier and faster. With
programming software, we can write programs in high-level languages like C, C++, Java, or
Python, and then convert them into machine language for the computer to understand.
Examples of Programming Software:
 Compilers – Convert source code into machine code.
 Interpreters – Translate and run code line by line.
 Debuggers – Help find and correct errors in programs.
 Linkers – Combine object files with library functions.
 Text Editors – Simple editors like Notepad or IDEs used to write code.

Application Software:

Application software is the software made for the end user to perform specific tasks. It is the
software we use in daily life for study, business, entertainment, and communication. This
software runs on top of the system software. For example, when we browse the internet, play a
game, or prepare a project report, we are using application software.

Examples of Application Software:

 Business Software – Payroll, billing, or accounting systems.


 Educational Software – Learning tools, exam preparation apps.
 Databases – Oracle, MySQL for storing and retrieving data.
 Decision-making Software – Tools that help in planning and forecasting.
 Image Editing Software – Photoshop, GIMP.
 Web Browsers – Chrome, Firefox, Edge.

1.2 Introduction to Program Languages:

COMPUTER LANGUAGES

Programs in high-level languages cannot be used to control the CPU directly. Software’s to
translate programs from a high-level language to some assembly language or machine language
is necessary. Such a system software is called a compiler or an interpreter.

In order to communicate with the computer user also needs to have a language that should be
understood by the computer. For this purpose, different languages are developed for performing
different types of work on the computer. Basically, languages are divided into two categories
according to their interpretation.
1. Low Level Languages. 2. High Level Languages.

1.2.1. Low Level Languages:

Low level computer languages are machine codes or close to it. Computer cannot understand
instructions given in high level languages or in English. It can only understand and execute
instructions given in the form of machine language i.e. language of 0 and 1. There are two types
of low level languages:

Machine Language. Assembly Language

1.2.1 a. Machine Language:

Machine language is the oldest and simplest programming language. It is the only language that
a computer can directly understand and run. Every computer is made by the company to work
with its own machine code. This machine code is written in binary numbers, which is 0 and 1.
Here, 0 means no electric signal, and 1 means an electric signal is present. Since computers work
with electronic signals, they can easily understand and carry out instructions written in machine
language.

1.2.1. b Assembly Language

Assembly language was developed to make programming a little easier. In this language, instead
of writing instructions in 0s and 1s, we use short codes called mnemonics. For example, ADD is
used for addition and SUB is used for subtraction. A program called assembler is required to
convert assembly language into machine language so that the computer can understand it.
Assembly language is easier than machine language, but still difficult compared to modern
languages.

1.2.2. High-Level Language

High-level languages were developed to make programming simple for humans. In these
languages, we can write instructions in words similar to English. Examples are C, C++, Java,
and Python. A compiler or interpreter is used to translate high-level language into machine
language. High-level languages are much easier to learn, understand, and use for writing
programs. They are also portable, which means the same program can run on different types of
computers.
What is C Language?

C is a programming language that was developed in 1972 at AT&T’s Bell Laboratories,


USA. It was designed and written by Dennis Ritchie, who is also called the founder of C
language. C language was created to solve the problems of older languages like B and BCPL. It
was mainly developed to be used in the UNIX operating system, which was also written in C.
Because of its simplicity, efficiency, and power, C became one of the most popular
programming languages and is still widely used today.

Features of C Language

1. Simple and Easy to Learn


o C is easy to understand because it uses simple keywords and structure.
o Even beginners can learn it step by step.
2. Middle-Level Language
o C is called a middle-level language because it has features of both low-level
(machine level) and high-level languages.
o This makes it suitable for system programming as well as application
programming.
3. Portable Language
o A C program written on one computer can run on another computer with little or
no changes.
o Example: A program written on Windows can also run on Linux.
4. Efficient and Fast
o Programs written in C are very fast and memory efficient.
o This is why C is often used for system software like operating systems.
5. Rich Library
o C has many built-in functions (library functions) like printf, scanf, sqrt, etc.
o These functions make programming easier.
6. Structured Programming Language
o C allows us to break a big program into smaller parts called functions.
o This makes programs easier to write, debug, and maintain.
7. Extensible Language
o We can add our own functions and use them in programs.
o This increases the reusability of code

Advantages of C Language

1. Widely Used and Popular


o C is one of the most popular programming languages.
o It is used in education, research, and software development.
2. Foundation for Other Languages
o Many modern languages like C++, Java, Python, and C# are influenced by C.
o Learning C makes it easier to learn other languages.
3. Used in System Programming
o C is used to develop operating systems (like UNIX, Linux) and embedded
systems.
o It gives access to low-level memory and hardware.
4. Reusability of Code
o Functions and modules can be reused in different programs.
o This saves time and effort.
5. Fast Execution
o C programs run faster compared to many high-level languages.
o This makes it suitable for games, drivers, and real-time applications.

Application of C Language

 C language is being used since the early days of computer programming and still is used
in wide variety of applications such as:
 C is used to develop core components of operating systems such as Windows, Linux, and
mac OS.
 C is applied to program embedded systems in small devices such as washing machines,
microwave ovens, and printers.
 C is utilized to create efficient and quick game engines. For example, the Doom video
game engine was implemented using C.
 C is employed to construct compilers, assemblers, and interpreters. For example, the C
Python interpreter is written partially using C.
 C is applied to develop efficient database engines. The MySQL database software is
implemented using C and C++.
 C is employed to create programs for devices and sensors of Internet of Things (IoT). A
common example is a house automation system comprising temperature sensors and
controllers that is often prepared with C.
 C is employed for creating lightweight and speedy desktop applications. The widely used
text editor Notepad++ employs C for performance-sensitive sections.

History of C Language

1. Origin and Development

 C language was developed in the early 1970s at Bell Laboratories (AT&T, USA) by
Dennis Ritchie.
 It was created as an improvement over the B language, which itself was derived from
BCPL (Basic Combined Programming Language).
 The main motivation behind C was to develop a language suitable for writing system
software, especially the UNIX operating system, while being efficient, flexible, and
portable.

2. Key Influences

 BCPL (1966): A simple language for writing compilers and operating systems.
 B (1969): Developed by Ken Thompson, based on BCPL, but lacked data types like int
and char.
 C (1972): Added data types, structured programming constructs, and low-level memory
access, making it powerful for both system and application programming.

3. Features Introduced by C

 Low-level access: Ability to directly manipulate memory using pointers.


 Structured programming: Support for functions, loops, and conditional statements.
 Portability: Programs written in C could be easily adapted to different machines.
 Efficiency: Close to assembly language in performance while being easier to read and
write.

4. Standardization

 Initially, C was known as “K&R C”, named after Brian Kernighan and Dennis
Ritchie, who published “The C Programming Language” in 1978.
 In 1983, the American National Standards Institute (ANSI) formed a committee to
standardize C.
 The first official standard, ANSI C, was published in 1989 (also called C89).
 Later, the International Organization for Standardization (ISO) adopted it as ISO C
in 1990.
 Subsequent revisions include C99, C11, and C18, introducing new features like inline
functions, better support for data types, and multithreading capabilities.

5. Importance and Legacy

 C is called the “mother of modern programming languages” because many languages


like C++, C#, Java, and Python are heavily influenced by C.
 It remains widely used for system programming, embedded systems, compilers, and
operating systems.
Basics of computer program Algorithms

There is a close analogy between learning English language and learning C language. The
classical method of learning English is to first learn the alphabets used in the language, then
learn to combine these alphabets to form words, which in turn are combined to form sentences
and sentences are combined to form paragraphs. Learning C is similar and easier. Instead of
straight-away learning how to write programs, we must first know what alphabets, numbers and
special symbols are used in C, then how using them constants, variables and keywords are
constructed, and finally how are these combined to form an instruction. A group of instructions
would be combined later on to form a program.
a computer program is just a collection of the instructions necessary to solve a specific problem.
The basic operations of a computer system form what is known as the computer’s instruction
set. And the approach or method that is used to solve the problem is known as an algorithm.

Algorithm:

1.2.3. Execution of C Program

Step 1: Writing and Editing the Program

 First, we write the program using a text editor (like Notepad or the built-in editor in a C
compiler).
 The program is written in C language according to the problem or requirement.
 After writing, the program is saved with the extension “.c”.
 Example: learnc.c

Step 2: Compiling the Program

 The computer does not understand C language directly. It only understands machine
language (0 and 1).
 The compilation is a process of converting the source code (High level language) into
object code (Machine Language). It is done with the help of the compiler.
 The compiler also checks for errors in the program.
 If there are no errors, the source code is converted into an object file with extension
“.obj”.

Step 3: Linking the Program

 C language has many library functions (like printf, scanf) which are stored in header
files.
 The linker combines the object file with the required library functions.
 After linking, an executable file is created with the extension “.exe”.

Step 4: Loading the Program

 Before running, the program must be moved from secondary storage (like hard disk) to
the main memory (RAM).
 This process is called loading, and it is done by a program called the loader.

Step 5: Executing the Program

 Finally, the program starts running.


 The instructions are carried out step by step.
 The output of the program is displayed on the screen.
Binary Number System – Simple Explanation

In computers, we mostly use the binary number system.

 Binary means base-2.


 It uses only two symbols: 0 and 1.
 These 0s and 1s are called bits.

Every computer stores and processes all kinds of data—numbers, text, images, sound—using
only 0s and 1s.

Basic Terms in Binary System

1. Bit → Smallest unit of data. Can be 0 or 1.


Example: 0, 1
2. Nibble → 4 bits together.
Example: 1010
3. Byte → 8 bits together. (Comes from “by eight”).
Example: 10110011
4. Word → 16 bits (2 Bytes).
5. Double Word → 32 bits (4 Bytes).
6. Kilobyte (KB) → 1024 Bytes.
7. Megabyte (MB) → 1024 KB.
8. Gigabyte (GB) → 1024 MB.
Binary to Decimal Conversion Table (0 – 15)

Decimal (Base-10) Binary (Base-2) Calculation (Binary → Decimal)


0 0000 0
1 0001 1
2 0010 (2¹) = 2
3 0011 (2¹ + 2⁰) = 2 + 1 = 3
4 0100 (2²) = 4
5 0101 (2² + 2⁰) = 4 + 1 = 5
6 0110 (2² + 2¹) = 4 + 2 = 6
7 0111 (2² + 2¹ + 2⁰) = 4 + 2 + 1 = 7
8 1000 (2³) = 8
9 1001 (2³ + 2⁰) = 8 + 1 = 9
10 1010 (2³ + 2¹) = 8 + 2 = 10
11 1011 (2³ + 2¹ + 2⁰) = 8 + 2 + 1 = 11
12 1100 (2³ + 2²) = 8 + 4 = 12
13 1101 (2³ + 2² + 2⁰) = 8 + 4 + 1 = 13
14 1110 (2³ + 2² + 2¹) = 8 + 4 + 2 = 14
15 1111 (2³ + 2² + 2¹ + 2⁰) = 8+4+2+1=15

TRANSLATOR PROGRAMS

Assembler:

An assembler is a computer program that converts assembly language instructions into


machine language codes. Assembly language uses short forms or mnemonics such as ADD,
MOV, or JMP, which are easier for humans to read. The assembler translates each of these
instructions into a stream of 0s and 1s, called the object code or machine code. This machine
code is the final form that the computer can directly execute to perform the required task.

Assemblers are mainly of two types: single-pass and two-pass assemblers. A single-pass
assembler reads the program once and directly replaces mnemonics with binary codes. However,
it cannot handle complex optimizations. To overcome this, the two-pass assembler was
developed. In the first pass, it collects all symbolic names (like labels and variables) and stores
them in a symbol table. In the second pass, it replaces these names with actual addresses, which
leads to better optimization and accuracy in the generated machine code.

Complier

A compiler is a computer program that translates source code written in a high-level


language (like C, C++, FORTRAN, COBOL) into low-level machine code. This process is called
compilation, and the final output is an executable file. The reverse of a compiler is called a
decompiler, which converts low-level code back into high-level code. Initially, compilers were
written in assembly language, but today many compilers are written in the same language they
are designed to compile. Compilers are mainly of two types: single-pass and multi-pass. Single-
pass compilers are faster but less powerful, while multi-pass compilers take more time but
provide better optimization and generate higher-quality code.

Intepreter

An interpreter is a translation program that converts each high-level language statement into
machine code just before execution. Unlike a compiler, which translates the whole program at
once, the interpreter works line by line, translating and executing statements immediately.

Languages like BASIC and PERL are commonly interpreted. Interpreters are generally easier to
create compared to compilers. However, programs run by interpreters are usually slower, while
compiled programs run faster and more efficiently.

Difference between complier, Interpreter and Translator

Feature Compiler Interpreter Translator (General)


Definition Converts the entire high- Converts high-level A general program that
level program into program line by line into converts code from one
machine code at once. machine code and language to another (can be
executes immediately. compiler, interpreter, or
assembler).
Execution Executes after full Executes each line May or may not execute;
compilation. immediately after main job is just conversion.
translation.
Speed Faster execution (since Slower execution (line- Depends on type (compiler-
entire program is already by-line translation takes based translator is fast,
compiled). time). interpreter-based is slower).
Error Shows all errors after Shows errors Depends on the type of
Handling compilation. immediately (line by translator used.
line).
Memory Requires more memory Requires less memory Varies with type
Usage (stores object (no separate object code). (assembler, compiler, or
code/executable). interpreter).
Examples C, C++, FORTRAN, BASIC, PERL, Python Compiler, Interpreter,
COBOL (traditionally) Assembler are all
translators.

Problem-Solving Techniques

In today’s world, computers are widely used to solve different types of problems because they
work much faster than humans. To solve any problem using a computer, a systematic approach is
[Link] first step is to analyze the given problem and understand what needs to be solved.
Next, the solution process is broken down into a series of smaller, simple tasks. After that, an
algorithm is created, which is a step-by-step method to solve the [Link] algorithm is then
written in a programming language to form a computer program. The program is fed into the
computer, and the CPU interprets and processes the data according to the instructions. Finally,
the output unit displays the result for the user.

Structure of C program

A C program has a well-defined


defined structure
structure,, and understanding it is important for writing correct
and readable programs. The structure includes different sections,, each serving a specific
purpose.

0. Documentation section

 Used for comments

 Not executed by the compiler.


 Single-line: // comment
 Multi-line: /* comment */

1. Preprocessor Directives

 These are instructions that start with # and are processed before compilation.
compilation
 Commonly used to include header files or define constants.
 Example:

#include <stdio.h> // Include standard input/output library


#define PI 3.14 // Define constant

2. Global Declarations

 Variables or functions declared outside all functions.


 Accessible by all functions in the program.
 Example:
 int count = 0; // Global variable

3. main() Function

 Every C program must have a main() function where execution begins.


 It contains statements that perform the program’s tasks.
 Syntax:

int main() {

// Body of the program

return 0;

4. Local Declarations

 Variables declared inside a function.


 Accessible only within that function.
 Example:

int main() {

int num; // Local variable

5. Statements & Expressions

 Instructions that perform actions like calculations or I/O operations.


 Example:

printf("Hello, World!\n");

num = 5 + 3;

6. Functions
 Functions divide the program into smaller modules.
 Each function performs a specific task and can return a value.
 Syntax:

int add(int a, int b) {

return a + b;

Algorithm:

An algorithm is a detailed, step-by-step method for solving a problem. It is written in such a way
that it is independent of computer hardware or software. Algorithms are important because they
tell the computer exactly what steps to follow in order to complete a task or solve a problem.

Example: Algorithm: Sum of Two Numbers

Step 1: Start

Step 2: Input two numbers (say A and B)

Step 3: Add the two numbers → SUM = A + B

Step 4: Display the result (SUM)

Step 5: Stop

Algorithm: Prime Number Check

Step 1: Start

Step 2: Input a number N

Step 3: If N ≤ 1, then it is not prime, go to Step 8

Step 4: Set a counter i = 2

Step 5: Repeat Steps 6 and 7 while i ≤ N/2

Step 6: If N % i == 0, then N is not prime, go to Step 8


Step 7: Increase i by 1

Step 8: If no divisor found, then N is prime

Step 9: Stop

Example:

 Input: N = 7
 Check divisors from 2 to 3 (since 7/2 = 3.5)
 No divisor found → 7 is Prime

Algorithm: Find the Greatest of Three Numbers

Step 1: Start

Step 2: Input three numbers A, B, C

Step 3: If A > B and A > C, then

Print “A is the greatest” and go to Step 7

Step 4: Else if B > A and B > C, then

Print “B is the greatest” and go to Step 7

Step 5: Else if C > A and C > B, then

Print “C is the greatest” and go to Step 7

Step 6: If two or more numbers are equal, print “Two or more numbers are equal and
greatest”

Step 7: Stop

Example:

Input: A = 25, B = 30, C = 15

Compare → B is the greatest .

Write an algorithm for finding greatest among three numbers.

Let x, y and z be the numbers. Now, we can follow the algorithm below to determine the
greatest number
among the three:

1. Read the three numbers.

2. If x > y

a. If x > z, then x is the greatest number.

b. Else, z is the greatest number

3. Else,

a. If y > z, then y is the greatest number.

b. Else, z is the greatest number.

Write the algorithm for converting the degree in Celsius from Fahrenheit

Let us consider x to be the temperature given in Celsius. Now, we need to follow the
algorithm below to

Determine the temperature in Fahrenheit:

1. Read x

2. Multiply x with 9/5.

3. Add 32 to the multiplied result.

4. Print the fi nal value which is the temperature in Fahrenheit.

Write an algorithm to generate the Fibonacci series.

The above expression states that after two starting values, each number is the sum of two
preceding numbers. The algorithm for generating the Fibonacci series is:

1. Read the number of terms in the series, say n.

2. Set a = 0 and b = 1.
3. Print the value of a and b.

4. Set count = 2.

5. While count £ n, c = a + b.

6. Print the value of c.

7. Set a = b and b = c

Difference between Top-Down and Bottom-Up Approach in Algorithm Design

Aspect Top-Down Approach Bottom-Up Approach


Definition Problem is broken into smaller sub-Small components are solved first and
problems and solved step by step then combined to form the complete
(Divide & Conquer). solution.
Working Starts from the main problem and Starts from basic modules and builds
Style goes down to details. up to the main solution.
Flow From top (main problem) → down From bottom (sub-modules) → up
Direction (sub-problems) (main problem)
Example Binary Search, Merge Sort, Quick Sort
Dynamic Programming (Fibonacci,
Matrix Chain Multiplication)
Focus Focuses on breaking down a large Focuses on building up a large
problem into parts. solution from smaller parts.
Reusability Less reusable as sub-problems are More reusable as smaller modules can
designed for a specific problem. be applied in multiple problems.
Efficiency Sometimes redundant calculations Avoids redundancy by storing results
occur (e.g., recursive solutions). of sub-problems (e.g., DP uses
memorization).
Use Cases Searching and Sorting algorithms. Optimization problems (Shortest Path,
Knapsack Problem, Fibonacci).

Characteristics of Algorithms

1. Finiteness
o An algorithm must always terminate after a finite number of steps.
o Example: An algorithm to calculate the sum of two numbers will stop after the
calculation.
2. Definiteness (Clarity)
o Each step of the algorithm must be clear, precise, and unambiguous.
o Example: “Add A and B” is clear, but “do the calculation” is vague.
3. Input
o An algorithm should have zero or more inputs (values given initially).
o Example: To find the sum of two numbers, inputs are numbers A and B.
4. Output
o An algorithm must produce at least one output (the result).
o Example: In sum algorithm, the output is A + B.
5. Effectiveness
o Each step must be simple enough to be carried out using basic computations.
o It should not require anything impossible to perform.
6. Generality
o An algorithm should work for all valid inputs, not just for a specific case.
o Example: A prime number algorithm should work for any number, not only for 7
or 11.

Flow chart:

A flowchart is a diagrammatic representation of a process or algorithm. It uses symbols to


represent different types of actions or steps and arrows to show the flow of control from one step
to another. Flowcharts help visualize logic, processes, or workflows so they are easier to
understand.

Give a fl ow chart for addition of two numbers.

Give a fl ow chart to print he average of three numbers.


Give a flowchart for finding greatest among three numbers.
Pseudo code: Pseudo code is a high-level description of an algorithm that uses plain English (or
simple programming-like statements) instead of actual programming syntax. It’s not executable,
but it helps you plan your program logically before writing real code.

Key Points:

 Uses structured English statements.


 Focuses on logic, not syntax.
 Helps programmers think through problems.
 Usually uses keywords like START, END, IF, ELSE, FOR, WHILE.

Problem 1: Sum of Two Numbers

START

INPUT number1

INPUT number2

sum = number1 + number2

PRINT sum

END

Problem 2: Find the Largest of Three Numbers

START

INPUT num1, num2, num3

IF num1 > num2 AND num1 > num3 THEN

PRINT num1 "is largest"

ELSE IF num2 > num3 THEN

PRINT num2 "is largest"

ELSE

PRINT num3 "is largest"

END.
Problem 3: Check if a Number is Even or Odd

START

INPUT number

IF number MOD 2 = 0 THEN

PRINT "Even"

ELSE

PRINT "Odd"

END

Difference between flowchart , algorithm and pseudo code

Feature Flowchart Algorithm Pseudocode


Definition A graphical A step-by-step A plain English or
representation of steps procedure to solve a structured code-like
in a process using problem in logical description of an
symbols and arrows. order. algorithm.
Representation Visual diagram with Textual description in Textual description
shapes (oval, rectangle, sequential steps. resembling code but
diamond, etc.). not actual code.
Purpose Shows the flow of Provides a logical Bridges the gap
control and decision- roadmap to solve a between algorithm and
making visually. problem. programming; helps
implement the
algorithm in code.
Symbols/Notations Uses symbols: oval No symbols; just No symbols; uses
(start/end), rectangle numbered or bulleted structured English
(process), diamond steps. statements with
(decision), arrows keywords like IF, FOR,
(flow). WHILE.
Complexity Can be complex for Simple to moderate; Moderate; easier to
large problems due to easy to write but may translate into code.
many symbols. require careful
ordering.
Execution Cannot be executed by Cannot be executed Cannot be executed
a computer. directly; needs directly; used as a
implementation in blueprint for coding.
code.
Ease of Very easy for Easy to follow; Slightly harder than
Understanding beginners; visual aid logical flow is flowchart for beginners
helps understanding. explicit. but closer to coding
logic.
Best For Visualizing process Planning problem- Preparing for actual
flow and decisions. solving steps coding in any
logically. programming language.

C Tokens

 In C, the smallest units of a program are called tokens.


 Tokens are like words and punctuation in a text.
 Programs are built by combining tokens according to syntax rule
 Types of C Tokens:
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Operators
6. Punctuators

KEYWORDS

Identifiers refer to the names of variables, functions and arrays. These are user-defined names.
Both uppercase and lowercase letters are permitted. The underscore character is also permitted in
identifiers.

Rules for Identifiers

1. First character must be an alphabet (or underscore).

2. Must consist of only letters, digits or underscore.

3. Only fi rst 31 characters are significant.

4. Cannot use a keyword.


5. Must not contain white space.

CONSTANTS

Constants in C refer to fixed values that do not change during the execution of a program. C
supports.

2. Numeric Constants

Numeric constants represent numbers. They are divided into:

a) Integer Constants

 Whole numbers without a fractional part.


 Can be positive, negative, or zero.
 Examples:

int age = 25; // 25 is an integer constant

int temp = -10; // -10 is an integer constant

b) Real Constants

 Numbers with a fractional part (decimal).


 Represent floating-point numbers.
 Examples

float pi = 3.14; // 3.14 is a real constant

double g = 9.81; // 9.81 is a real constant

3. Character Constants
Character constants represent characters or strings. They are divided into:

a) Single Character Constants

 A single character enclosed in single quotes (' ').


 Examples:

char grade = 'A'; // 'A' is a single character constant

char symbol = '#'; // '#' is a single character constant

b) String Constants

 A sequence of characters enclosed in double quotes (" ").


 Examples:

char name[] = "Ram"; // "Ram" is a string constant

char message[] = "Hello!"; // "Hello!" is a string constant.

C Language Data Types

C language offers a variety of data types that let programmers choose the most suitable type
depending on the needs of the program and the computer system.

C’s variety of data types gives flexibility to:

 Optimize memory usage.


 Match program needs to machine architecture.
 Improve precision in calculations.

By understanding primary, derived, and user-defined types, you can efficiently design programs
for different scenario.

ANSI C classifies data types into three main categories:

1. Primary (Fundamental) Data Types – Basic types built into C.


2. Derived Data Types – Created from primary types, like arrays, pointers, functions, and
structures.
3. User-Defined Data Types – Created by programmers using keywords like struct,
union, and enum.
4. 1. Primary (Fundamental) Data Types
5. These are the basic building blocks in C. All C compilers support five fundamental
types:
Data Type Purpose Example
int Stores whole numbers (integers) int age = 25;
char Stores single characters char grade = 'A';
float Stores decimal numbers (single precision) float temperature = 36.6;
double Stores decimal numbers with higher precision double pi = 3.141592;
void Represents no value or empty return type void function() { }

2. Derived Data Types

Derived data types are based on the primary data types. Examples:

 Arrays → Collection of elements of the same type.


int numbers[5] = {1, 2, 3, 4, 5};
 Pointers → Store addresses of variables.
int *ptr = &age;
 Functions → Can return values of any data type.
 Structures → Group different types under one name

3. User-Defined Data Types

Programmers can create their own data types using:

 struct → Group variables of different types.


 union → Store different types in the same memory location.
 enum → Define a set of named integer constants.
 typedef → Create a new name for an existing type.

Common questions

Powered by AI

Input and output units facilitate user-computer interaction by acting as intermediaries that translate human-readable data into a machine-readable format and vice versa. Input units, such as keyboards and mice, convert user commands into binary code understood by the computer. Conversely, output units, like monitors and printers, take processed data from the computer and present it in a form comprehensible to humans. This dual conversion process allows for seamless communication between the user and the computer, enabling effective data entry and retrieval of results .

The Von Neumann architecture influences modern computer processing primarily through its memory and CPU design. It establishes the stored program concept, wherein both instructions and data are stored in the same memory space, allowing for greater flexibility and efficiency in processing. Modern computers maintain this fundamental architecture with a central processing unit (CPU) consisting of an arithmetic logic unit (ALU) for performing calculations, and a control unit (CU) for directing instructions. This setup facilitates complex computations and control processes, forming the foundation of computer operation and program execution .

The evolution from vacuum tubes to microprocessors significantly improved computational speed and reduced physical size across computer generations. First-generation computers utilized vacuum tubes, which had slow operation speeds in milliseconds and were very large in size, exemplified by systems like the ENIAC. The transition to second-generation transistors reduced size and increased speed to microseconds. With integrated circuits (ICs) in the third generation, size decreased further, and operation moved to nanoseconds, allowing the development of mini computers such as the IBM 360. The fourth generation's use of microprocessors, like the Intel 4004, reduced size to micro/PC scale and increased speed to picoseconds. Finally, the fifth generation's use of VLSI/ULSI technology has enabled very small computers and extremely high speeds, culminating in AI systems and neural networks .

Primary memory, consisting of RAM and ROM, is directly accessible by the CPU and features faster data access though with limited size. It is volatile (except for ROM), meaning it loses data when power is off, and stores data and instructions for quick access during processing. In contrast, secondary memory, such as HDDs and SSDs, offers larger, permanent storage at slower access speeds. The data from secondary memory must first transfer to the primary memory for the CPU to process it, reflecting a hierarchical interaction that balances performance and storage capacity .

The technological innovations from first to fifth-generation computers exhibit significant functionality enhancements. First-generation computers with vacuum tubes were limited by their size and processing speed. The second generation, with the introduction of transistors, saw reductions in size and improvements in speed. The third generation's integrated circuits further decreased size and increased speed, allowing more powerful computation like the IBM 360. Fourth-generation microprocessors revolutionized both size and speed, facilitating the advent of personal computing. Fifth-generation technology, involving AI and VLSI/ULSI, introduces capabilities of deep learning and neural processing, marking a leap towards smart and autonomous computing systems, highlighting a trajectory of increasing complexity and capability .

The memory hierarchy optimizes computer performance through a structured tier system that balances speed, size, and cost. At the top, registers and cache memory offer rapid data access, crucial for frequently used instructions, thus minimizing CPU waiting time. Main memory (RAM) provides larger but slower storage for active processes, whereas secondary memory, like HDDs and SSDs, offers massive and economic data storage though at slower speeds. By ensuring data is staged through progressively faster tiers before reaching the CPU, the hierarchy minimizes bottlenecks, effectively speeding up processing and efficiently utilizing resources .

Compilers and interpreters serve as critical tools in executing high-level programming languages by translating them into machine language so that the computer can execute instructions. Compilers translate entire high-level language programs into machine code before execution, allowing the program to run faster once compiled. In contrast, interpreters translate and execute code line-by-line, which simplifies debugging and offers more immediate program testing. Both tools make high-level languages accessible for practical applications by enabling compatibility with the machine's binary language .

Machine language, consisting of binary code, offers unparalleled execution speed and efficiency because it directly communicates with a computer's CPU without translation. However, it is difficult for humans to read, write, and debug due to its complexity and specificity to hardware. High-level languages, on the other hand, are designed to be user-friendly, often resembling natural language, making them easier to write, debug, and maintain. They are also portable across different systems due to compilers and interpreters. While machine language is unparalleled in performance efficiency, high-level languages provide significant advantages in development speed, accessibility, and flexibility .

Cache memory optimizes computer performance by reducing latency between the CPU and the main memory. As very high-speed memory strategically placed between the CPU and RAM, cache stores frequently accessed data and instructions to minimize the time the CPU takes to retrieve them from slower main RAM. By having instructions readily available, cache effectively accelerates processing speed, leading to overall improved system performance. This hierarchy ensures that the most critical data for current operations are accessed faster, reducing overall system delay .

Programming languages like C have heavily influenced modern programming practices and software development by establishing fundamental syntax and features used in many contemporary languages. C's characteristics, such as its structured programming paradigm, ease of understanding, and portability, make it foundational for systems programming and application development. Furthermore, modern languages like C++, Java, and Python draw influence from C, inheriting its efficiency and capability for low-level data manipulation. C's influence extends to the development of operating systems, game engines, and embedded systems, showcasing its significance in performance-critical applications .

You might also like