0% found this document useful (0 votes)
5 views14 pages

Theory Note Final

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

Theory Note Final

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

 What are the main components of a computing device?

(20-21)

The main components of a computing device are:

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.

 Differences Between Hardware and Software:

Aspect Hardware Software

Definition Physical components of a computer. Set of instructions to perform tasks.

Operating System, MS Word, C


Examples CPU, RAM, Hard Drive.
Compiler.

Tangible/Intangible Tangible Intangible

Software is required to operate


Dependency Requires hardware to run.
hardware.
 What are the main components of a C program?(20-21)

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:

 #include: Includes standard or user-defined libraries (e.g., #include <stdio.h>).


 #define: Defines constants or macros.

2. Header Files

Header files provide predefined functions and macros to simplify programming. Common header
files in C include:

 <stdio.h>: For standard input/output functions (printf, scanf).


 <math.h>: For mathematical operations (sqrt, pow).
 <string.h>: For string manipulation functions (strlen, strcpy).

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

This section includes:

 Declaration of variables (e.g., int a, b;).


 Declaration of constants using const or #define.
 Declaration of functions (if necessary) with their prototypes.

5. Statements/Instructions

This is the core of the program where all the logical operations, computations, and function calls
are performed. It includes:

 Input/Output Statements: For user interaction (e.g., printf, scanf).


 Control Flow Statements: For decision-making and looping (e.g., if, for, while).
 Function Calls: To execute predefined or user-defined functions.

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 and output functions in C:

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.

a. Input Function: scanf()

The scanf() function is used to read data from the user.

 It requires a format specifier to specify the type of data to be entered.

b. Output Function: printf()

The printf() function is used to display data to the user.

 It also uses format specifiers to specify the type of data.

 Differences Between Variables and Constants in C

Aspect Variable Constant


A variable is a named memory location A constant is a fixed value that
Definition whose value can change during program cannot change during program
execution. execution.
Declared using a data type like int, Declared using const keyword or
Declaration
float, etc. #define.
Value The value of a variable can be updated at The value of a constant is fixed and
Modification any time. cannot be modified.
const int MAX = 100; or
Syntax int age = 20;
#define PI 3.14
Storage in Similar to variables, but the value is
Allocated memory to store its value.
Memory protected.
Scope Follows variable scope rules (local or Scope depends on how it is defined
Aspect Variable Constant
global). (const or #define).
Used for storing data that may change Used for defining fixed values like
Use Case
during execution. PI, conversion factors, etc.

 What are local and global variables?(20-21)


There are two places where variables are declared: inside a function
or outside all functions. Variables declared outside all functions are
called, global variables and they may be accessed by any function in
your program. Global variables exist the entire time your program
is executing.
Variables declared inside a function are called local variables. A local
variable is known to—and may be accessed by—only the function in
which it is declared.

 Precedence and associativity in C:


Precedence defines the priority of operators. Operators with higher precedence are evaluated
first. Operators with higher precedence are evaluated first. Operators with the same precedence
follow associativity rules.
Associativity defines the direction (left-to-right or right-to-left) in which operators of the same
precedence level are evaluated.

 Operator Precedence Table with Descriptions (Green marked are important for
exam, skip the rest)

Precedence
Operator(s) Associativity Description
Level

(): Parentheses for grouping expressions. Example: (a + b) * c


evaluates a + b first.
1 (Highest) () [] -> . Left-to-right []: Array access. Example: arr[2] accesses the 3rd element of arr.
->: Access struct member via pointer. Example: ptr->member.
.: Access struct member. Example: structVar.member.

2 ++ -- + - ! ~ * & Right-to-left ++: Increment. Example: i++ is equivalent to i = i + 1.


sizeof --: Decrement. Example: i-- is equivalent to i = i - 1.
+ -: Unary plus/minus. Example: -a negates a.
!: Logical NOT. Example: !1 is 0.
~: Bitwise NOT. Example: ~5 flips the bits of 5.
*: Dereference pointer. Example: *ptr gets the value stored at ptr.
&: Address-of operator. Example: &x gets the address of x.
sizeof: Returns size of a type or variable. Example: sizeof(int) gives
Precedence
Operator(s) Associativity Description
Level

4 bytes (on most systems).

*: Multiplication. Example: 5 * 3 = 15.


3 */% Left-to-right /: Division. Example: 10 / 2 = 5.
%: Modulus (remainder). Example: 10 % 3 = 1.

+: 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.

==: Equality. Example: 5 == 5 is 1 (true).


7 == != Left-to-right
!=: Inequality. Example: 5 != 3 is 1 (true).

Bitwise AND: Operates at the bit level. Example: 5 & 3 is 1 (0101 &
8 & Left-to-right
0011 = 0001).

Bitwise XOR: Exclusive OR. Example: 5 ^ 3 is 6 (0101 ^ 0011 =


9 ^ Left-to-right
0110).

10 ` ` Left-to-right

Logical AND: Returns 1 if both operands are non-zero. Example: 5 && 3 is


11 && Left-to-right
1.

12 ` `

Ternary Operator: Short if-else. Example: (5 > 3) ? 10 : 20 evaluates


13 ? : Right-to-left
to 10.

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.

Comma Operator: Evaluates expressions from left to right, returning the


15 (Lowest) , Left-to-right value of the rightmost expression. Example: x = (1, 2, 3); assigns 3
to x.

 Arithmetic Operators used in C:


Here are the operators used in arithmetic expressions:

Operator Name Example Description

+ Addition a + b Adds two values.

- Subtraction a - b Subtracts the second value from the first.

* Multiplication a * b Multiplies two values.

/ Division a / b Divides the first value by the second.

% Modulus a % b Finds the remainder when a is divided by b. (Only for integers.)

 Assignment Statements:

Assignment statements are used to assign values to variables. Shortcut versions of assignment
statements that combine arithmetic operations and assignment:

Operator Equivalent To Example Description


+= x = x + y x += 5; Adds y to x and stores the result in x.
-= x = x - y x -= 3; Subtracts y from x and stores the result.
*= x = x * y x *= 2; Multiplies x by y and stores the result.
/= x = x / y x /= 4; Divides x by y and stores the result.
%= x = x % y x %= 3; Calculates x % y and stores the result.

 What is a compiler? Why do we need a compiler to run a C program?


A compiler in C programming acts as a translator, converting human-readable C code into
machine-readable instructions that a computer can execute. We need a compiler to run a C
program because computers only understand machine code, consisting of binary instructions.
Without a compiler, the computer wouldn't be able to interpret and execute the instructions
written in C language. In essence, the compiler bridges the gap between our programming
language and the computer's language, making it possible for us to create and run software.

 In which function does a c program start executing?(20-21)


Although a C program may contain several functions, the only function that it must have is main( ).
The main( ) function is where execution of your program begins. That is, when your program begins
running, it starts executing the statements inside main( ), beginning with the first statement after
the opening curly brace. Your program ends when main( )'s closing curly brace is reached. Of course,
the curly brace does not actually exist in the compiled version of your program, but it is helpful to
think of it in this way.
 Differentiate between a compiler and an interpreter.(20-21)

Feature Compiler Interpreter

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.

 What are the associativity of ++ and != in C programming?


(20-21 & 19-20)
The ++ operator has a right-to-left associativity. This means that if multiple ++
operators appear next to each other in an expression, they are evaluated from
right to left.
The != operator has a left-to-right associativity. This means that if multiple !=
operators appear next to each other in an expression, they are evaluated from
left to right.

 Data Types in C:

C has several data types, categorized as follows:

 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.

 Why do we use functions? Differentiate between passing a parameter in a function


by value and passing by reference using example.(20-21)

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.

Passing a Parameter by Value vs. Passing by Reference

Aspect Pass by Value Pass by Reference

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.

 Use of break to exit a loop:


The break statement allows you to exit a loop from an y point within

its body, bypassing its normal termination expression. When the break

the statement is encountered inside a loop, the loop is immediately

stopped, and program control resumes at the next statement following the loop.

All the Definitions

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

 An array is a collection of variables of the same type stored in contiguous memory


locations.

 Difference between array and regular variable:


Aspect Regular Variable Array
Stores a single value of a Stores multiple values of the same data type in
Storage of Data
specific data type. contiguous memory locations.
Occupies memory based on the number of
Size and Occupies memory based on
elements, with each element taking up the size of
Memory the size of the data type
the data type (e.g., int arr[5] uses 5 times the
Allocation (e.g., 4 bytes for an int).
size of int).

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

 A pointer is a variable that stores the memory address of another variable.

8. Sorting

 Sorting arranges elements in a specific order (ascending or descending).


9. Linear Search

 Linear search checks each element in an array one by one until the desired element is
found or the list ends.

10. Binary Search

 Binary search divides the sorted array into halves to find the target element efficiently.

You might also like