Theory Note Final
Theory Note Final
(20-21)
1. Central Processing Unit (CPU): The "brain" of the computer, responsible for processing
instructions and performing calculations.
2. Memory (RAM): Temporary storage for data and instructions currently being used by
the CPU.
3. Storage: Permanent storage for data and software, such as Hard Drives (HDD), Solid-
State Drives (SSD), or Flash Memory.
4. Input Devices: Devices used to provide data to the computer, such as a keyboard, mouse,
or microphone.
5. Output Devices: Devices that display or output information, such as monitors, printers,
or speakers.
6. Motherboard: The main circuit board connecting all components, including the CPU,
memory, and peripherals.
7. Power Supply Unit (PSU): Converts electrical power into usable forms for the
computer's components.
8. Networking Components: Devices or adapters for connecting to networks, like Ethernet
cards or Wi-Fi adapters.
Computer Hardware
Hardware refers to the physical components of a computer system. These are the tangible parts
that you can see and touch.
Classification of Hardware:
1. Input Devices:
o Devices used to enter data into a computer.
o Examples: Keyboard, Mouse, Scanner, Microphone, Touchpad.
2. Processing Devices:
o Components responsible for processing the data.
o Example: CPU (Central Processing Unit), GPU (Graphics Processing Unit).
3. Storage Devices:
o Devices used to store data permanently or temporarily.
o Types:
Primary Storage: RAM, ROM.
Secondary Storage: Hard Disk Drives (HDD), Solid State Drives (SSD),
Optical Discs (CD/DVD).
Tertiary Storage: Magnetic Tapes, Cloud Storage.
4. Output Devices:
o Devices that provide processed data as output.
o Examples: Monitor, Printer, Speakers.
5. Communication Devices:
o Components that enable data transfer between computers.
o Examples: Network Interface Card (NIC), Modems, Routers.
Computer Software
Software refers to a set of instructions or programs that enable the hardware to perform tasks.
Software is intangible.
Classification of Software:
1. System Software:
o Provides the interface between hardware and user applications.
o Examples:
Operating Systems: Windows, Linux, macOS.
Utility Programs: Antivirus, Disk Cleanup tools.
2. Application Software:
o Programs designed for end-users to perform specific tasks.
o Examples: MS Office, Web Browsers (Chrome, Firefox), Media Players.
3. Development Software:
o Tools used by programmers to develop applications.
o Examples: Compilers, Debuggers, Text Editors (e.g., Visual Studio Code), IDEs
(e.g., Eclipse).
4. Middleware:
o Software that acts as a bridge between applications or between systems.
o Examples: Database Middleware, Application Servers.
1. Preprocessor Directives
Preprocessor directives begin with # and instruct the compiler to perform specific actions before
the actual compilation of the program. Commonly used directives include:
2. Header Files
Header files provide predefined functions and macros to simplify programming. Common header
files in C include:
3. main() Function
The main() function is the entry point of every C program. The execution of the program starts
from this function. It is mandatory in all C programs.
4. Declaration Section
5. Statements/Instructions
This is the core of the program where all the logical operations, computations, and function calls
are performed. It includes:
6. Functions
A program can contain user-defined functions or calls to library functions. Functions improve
modularity and reusability in C programs.
7. Comments
Comments are used to make the code more readable. They are ignored by the compiler.
8. Return Statement
The return statement is used in functions to return a value to the calling function or terminate
the program.
Input refers to taking data from the user, and output refers to displaying data to the user. C
uses functions from the standard I/O library (<stdio.h>) for handling input and output
operations.
Operator Precedence Table with Descriptions (Green marked are important for
exam, skip the rest)
Precedence
Operator(s) Associativity Description
Level
+: Addition. Example: 5 + 3 = 8.
4 +- Left-to-right
-: Subtraction. Example: 10 - 7 = 3.
<<: Left shift. Example: 5 << 1 shifts bits of 5 left by 1, resulting in 10.
5 << >> Left-to-right
>>: Right shift. Example: 8 >> 1 shifts bits of 8 right by 1, resulting in 4.
Relational Operators:
<: Less than. Example: 5 < 10 is 1 (true).
6 < <= > >= Left-to-right <=: Less than or equal. Example: 5 <= 5 is 1.
>: Greater than. Example: 10 > 5 is 1.
>=: Greater than or equal. Example: 10 >= 10 is 1.
Bitwise AND: Operates at the bit level. Example: 5 & 3 is 1 (0101 &
8 & Left-to-right
0011 = 0001).
10 ` ` Left-to-right
12 ` `
Assignment Operators:
=: Assign value. Example: x = 5.
+=: Add and assign. Example: x += 2 is x = x + 2.
14 = += -= *= /= %= Right-to-left -=: Subtract and assign. Example: x -= 2.
*=: Multiply and assign. Example: x *= 2.
/=: Divide and assign. Example: x /= 2.
%=: Modulus and assign. Example: x %= 3.
Assignment Statements:
Assignment statements are used to assign values to variables. Shortcut versions of assignment
statements that combine arithmetic operations and assignment:
A program that translates the entire source A program that translates and
Definition
code into machine code before execution. executes the source code line by line.
Execution Executes the compiled code (machine code). Executes the source code directly.
Faster after compilation because the code is Slower because translation happens
Speed
already translated. during execution.
Produces an independent executable file Does not produce an independent file;
Output
(e.g., .exe). executes code immediately.
Displays all errors after analyzing the entire Displays errors one at a time as they
Errors
code. are encountered.
Examples C, C++, Java (for compilation to bytecode) Python, JavaScript, Ruby
Suitable for programs where performance is
Use Case Suitable for quick testing or scripting
critical.
Data Types in C:
Integer
o int: Allocates 4 bytes (1 byte = 8 bits).
o long: Allocates 8 bytes.
o short: Allocates 2 bytes.
Real Numbers
o float: A floating-point variable, uses 4 bytes.
o double: A double-precision floating-point variable, uses 8 bytes.
Character
o char: Used for characters, allocates 1 byte.
None
o void: Represents no value or nothing.
Garbage Values:
In C programming, a "garbage value" refers to an unpredictable and often
seemingly random value that is present in a variable when it is declared but not
initialized.
All C programs are composed of one or more functions. What is the name of the
function that all programs must have?
In C programming, all programs must have a function named main. This function is
the entry point of the program, meaning it is the first function that gets executed
when the program runs. The main function is crucial in C programs because it
serves as the entry point for execution. It can return an integer value to indicate the
success or failure of the program and can optionally accept command-line
arguments to provide input parameters.
Functions are used to break a large program into smaller, reusable blocks of code. They help
improve code readability, reduce repetition, make debugging easier, and allow you to reuse the
same code multiple times with different inputs.
A copy of the actual value is passed to the The actual memory address of the
Definition
function. variable is passed.
Effect on Original The original variable is not affected by Changes made in the function affect
Variable changes in the function. the original variable.
Conditionals
If:
The if statement is one of C's selection statements (sometimes called
conditional statements). Its operation is governed by the outcome of a
conditional test that evaluates to either true or false. Simply put, selection statements make
decisions based upon the outcome of some condition.
In its simplest form, the if statement allows your program In
conditionally execute a statement. This form of the expression is shown here:
if (expression)
{
Statement
}
The expression may be any valid C expression. If the expression
evaluates as true, the statement will he executed. If it does nut the
statement is bypassed, and the line of code following the if is executed.
In C, an expression is true if it evaluates to any nonzero value. If it
evaluates to zero, it is false. The statement that follows an if is usually
referred to as the target of the if statement. Commonly, the expression inside the if
compares one value with another using a relational operator. A relational operator
tests how one value relates to another. For example, to see it one value
is greater than another, C uses the > relational operator. The outcome
of this comparison is either true or false.
if-else:
You tan add an else statement to the if. When this is done, the if
statement looks like this:
if (expression)
{
statement 1;
}
else
{
statement2;
}
If the expression is true, then the target of the if will execute, and the
else portion will be skipped. However, if the expression is false, then
the target of the if is bypassed, and the target of the else will execute.
Under no circumstances will both statements execute. Thus, the
addition of the else provides a two-way decision path.
Else-if:
In C programming, the else if construct is used to test multiple conditions
sequentially. It is part of the conditional control structures that allow you to execute
different blocks of code based on different conditions. The else if construct
provides a way to check multiple conditions after an initial if condition and before a
final else condition.
The program starts by evaluating condition 1.If condition 1 is true, the block
of code associated with it is executed, and the rest of the else if and else
blocks are skipped.If condition 1 is false, the program evaluates condition
2.If condition 2 is true, its associated block of code is executed, and the rest
of the else if and else blocks are skipped. This process continues for any
subsequent else if conditions. If none of the if or else if conditions are
true, the else block is executed.
Loops
while loop:
Another of C's loops is while It has this general form,
While (expression)
statement;
The while loop works by repeating its target as long as the expression is true.
When it becomes false, the loop stops. The value of the expression is
Checked at the top of the -loop. This means that if the expression is
false to begin with, the loop will not execute even once.
Do loop: C's final loop is do, which has this general form:
Do
(statements)
while
(expression);
The do loop repeats the statement or statements while the
expression is true. It stops when the expression becomes false. The do
loop is unique because it will always execute the code within the loop
at least once, since the expression controlling the loop is tested at the
bottom of the loop.
its body, bypassing its normal termination expression. When the break
stopped, and program control resumes at the next statement following the loop.
1. Nested Loops
A nested loop is a loop inside another loop. The inner loop executes completely for each
iteration of the outer loop.
2. Arrays
3. Multidimensional Arrays
Multidimensional arrays are arrays with more than one dimension, like tables (2D) or
cubes (3D).
4. Functions
A function is a block of code that performs a specific task and can be called multiple
times in a program.
5. Recursion
Recursion is when a function calls itself to solve smaller instances of the same problem.
6. Structures
A structure is a user-defined data type that groups related variables of different types.
Why do we need structure in C?
Structures in C are used to group different data types under one name, making it easier to
manage related data as a single unit. They improve code organization, and readability, and allow
you to store multiple pieces of related information (like a student’s name, age, and marks)
together. This is especially useful when working with complex data or passing large amounts of
data between functions, and it helps keep the code clean and efficient. Structures also support
arrays of structures, allowing you to manage multiple instances of related data.
7. Pointers
8. Sorting
Linear search checks each element in an array one by one until the desired element is
found or the list ends.
Binary search divides the sorted array into halves to find the target element efficiently.