KEMBAR78
Computer | PDF | Assembly Language | Computer Program
0% found this document useful (0 votes)
8 views14 pages

Computer

Uploaded by

rahaabadnan848
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)
8 views14 pages

Computer

Uploaded by

rahaabadnan848
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

Chapter 2: Programming in C Language

Definition of a Computer Program


A computer program is a set of instructions that tells a computer how to do something. It
can be simple or complex and is used in apps, websites, and more.

Syntax vs. Semantics

Syntax
It is the set of rules for writing code. It shows how to write commands the right
way. If you don’t follow the rules, the code won’t work. Good syntax helps
avoid errors.

Semantics
is about the meaning of the code. It checks if the code does what you want.
Even if the code is written correctly, it can still be wrong if the logic is bad.
Good semantics help get the right result.

Levels of Programming Languages


Low-Level Languages
Machine Language:
This is code made of 0s and 1s that the computer understands directly. It is hard
for people to read or write.
Example: 11011000 is a machine instruction.

Assembly Language:
This uses short words (called mnemonics) instead of 0s and 1s. It is easier than
machine code but still hard and needs hardware knowledge.
Example: MOV AX, BX moves data between parts of the computer.

High-Level Languages
High-level languages are easy for people to read and write. They hide complex
hardware details. There are different types:

Procedural Languages:
Use step-by-step instructions.
Example: C, Fortran
Structured Languages:
Use a clear and organized program structure.
Example: Pascal
Object-Oriented Languages:
Use objects and classes to model real things.
Example: Java, Python
Translators

Translators change code into machine language so the computer can understand
it. There are three main types:

1. Assembler:
Changes assembly code into machine code.
Example: MOV AX, BX becomes 0s and 1s.
2. Compiler:
Changes the whole high-level program into machine code before running.
Example: A C program is turned into an app.
3. Interpreter:
Reads and runs code line by line without turning it into machine code
first.
Example: Python runs using an interpreter.

Integrated Development Environment (IDE)

An IDE is a tool that helps you write and test code in one place. It makes coding
easier and faster. Common features include:

 Code Editor: To write and change code.


 Compiler and Debugger: To run and fix code.
 Version Control: To track code changes.
 Syntax Highlighting: To make code easier to read.
Header Files in C

Header files have ready-made code like functions and macros. They help make
coding easier and faster.

Examples:

 <stdio.h> – For input and output (like printf, scanf)


 <math.h> – For math functions (like sqrt, pow)
 <string.h> – For working with text (like strlen, strcpy)

Structure of a C Program

A C program has different parts to keep it clear and organized:

1. Preprocessor Directives:
Start with #. Used to include libraries and define constants.
Examples:

 #include<stdio.h> – Adds input/output functions


 #define PI 3.14 – Sets a constant value

2. Global Declarations (Optional):


Variables declared here can be used anywhere in the program. Use
carefully.
3. Main Function:
The starting point of every C program.
Example:
int main() { // code goes here

return 0;
}

4. Local Declarations and Statements:


Variables inside main() or other functions. Only used in that part.
5. Other Functions (Optional):
Extra functions to handle specific tasks and keep the code neat.
Comments in C
Comments help explain the code and make it easier to read. They do not affect
how the program runs. The compiler ignores them.

Types of Comments:
1. Single-Line Comments:
Start with // and go to the end of the line.
Example:
int a = 10; // set a to 10
2. Multi-Line Comments:
Start with /* and end with */. Good for longer notes.
Example:
/*
This code finds the area of a circle
using PI.
*/

Benefits of Using Comments

 Improved Readability:
Comments help explain what the code does, making it easier to
understand.
 Documentation:
They serve as notes for developers who will work on the code later.
 Debugging Aid:
You can comment out parts of the code while fixing issues, without
deleting them.
Fundamentals of Input & Output Handling in C Programming
Output Functions in C

1. putchar()
Used to display a single character.
Example:

#include <stdio.h>
int main() {
putchar('A');
return 0;
}

2. puts()
Displays a string followed by a newline.
Example:

#include <stdio.h>
int main() {
puts("Hello, World!");
return 0;
}

3. printf()
Displays formatted text or values.
Example:

#include <stdio.h>
int main() {
int age = 25;
float salary = 3000.50;
printf("Age: %d\n", age);
printf("Salary: %.2f\n", salary);
return 0;
}
Using Data Types and Format Specifiers in C

In C, we use format specifiers in printf() to display different types of data.

1. Integer: %d or %i
2. Float (Decimal): %f
3. Float (Exponential): %e or %E
4. Character: %c
5. Long Integer: %ld or %li
6. String: %s

Example Program:

#include <stdio.h>
int main() {
int decimal = 100;
float f_decimal = 123.456;
double d_decimal = 123456.789;
char letter = 'A';
long int large_number = 9876543210;
char string[] = "Hello, C World!";

printf("Decimal Integer: %d\n", decimal);


printf("Float (Decimal): %.2f\n", f_decimal);
printf("Float (Exponential): %e\n", f_decimal);
printf("Character: %c\n", letter);
printf("Long Integer: %ld\n", large_number);
printf("String: %s\n", string);
return 0;
}

Escape Sequences in C

Escape sequences are used to represent special characters within strings or


characters. These sequences start with a backslash \ and are used to represent
non-printable characters.

1. Alert: \a
2. Backspace: \b
3. Newline: \n
4. Carriage Return: \r
5. Tab: \t
6. Backslash: \\
7. Single Quotation Mark: \'
8. Double Quotation Mark: \"
9. Question Mark:
Assignment Operators in C

Assignment operators are used to give values to variables. C has simple and
shortcut assignment operators.

1. Assignment Operator (=):


o Gives a value to a variable.
2. Compound Assignment Operators:
o += : Adds the right value to the left.
o -= : Subtracts the right value from the left.
o *= : Multiplies the left value by the right.
o /= : Divides the left value by the right.
o %= : Gives the remainder when the left value is divided by the right.

#include <stdio.h>
int main() {
int num = 10;
num += 5; // num = num + 5
num -= 3; // num = num - 3
num *= 2; // num = num * 2
num /= 4; // num = num / 4
num %= 3; // num = num % 3
printf("Final value of num: %d\n", num); // Prints the final value of num
return 0;
}

Increment (++) and Decrement (--) Operators in C


The increment (++) and decrement (--) operators are used to increase or
decrease a variable by 1.
1. Increment Operator (++):
o Increases the value of a variable by 1.
2. Decrement Operator (--):
o Decreases the value of a variable by 1.
Logical Operators in C

Logical operators are used to combine multiple conditions.

1. AND (&&):
o Returns true if both conditions are true.
2. OR (||):
o Returns true if at least one of the conditions is true.
3. NOT (!):
o Reverses the logical state of its operand (true becomes false, and false
becomes true).

#include int main()


{ int a = 10, b = 5, c = 20;
printf("a > b && c > a: %d\n", a > b && c > a); // AND
printf("a > b || c < a: %d\n", a > b || c < a); // OR
printf("!(a == b): %d\n", !(a == b)); // NOT
return 0; }

Difference Between Assignment Operator (=) and Equal To Operator (==)

1. Assignment Operator (=):


o Gives a value to a variable.
o Example: x = 5; makes x equal to 5.
2. Equal To Operator (==):
o Compares two values to see if they are the same.
o Returns true if they are the same, false if not.
o Example: x == 5; checks if x is 5.

Difference Between Unary and Binary Operators

1. Unary Operators:
o Work with only one operand.
o Examples: ++ (increment), -- (decrement), ! (logical NOT), -
(negation).
2. Binary Operators:
o Work with two operands.
o Examples: + (addition), - (subtraction), * (multiplication), /
(division), && (AND), || (OR), == (equals).
Chapter 4: Control Structures in C Programming
Control Statement (Easy and Solid Definition):
A control statement is a command in programming that decides the flow of a
program—what to do next, whether to repeat something, or to make a choice
based on conditions.

Key Points:

 Controls the order in which code runs.


 Lets programs make decisions (e.g., if, switch).
 Lets code repeat (e.g., for, while).
 Can jump in code (e.g., break, continue, goto).

Examples in C:

 Conditional: if, if-else, switch


 Looping: for, while, do-while
 Jump: break, continue, goto

Conditional Statement (Easy and Worth It Definition):


A conditional statement lets a program make decisions. It runs a block of code
only if a condition is true, helping the program choose what to do.

Main Types in C:

1. if – Runs code if a condition is true.


2. if-else – Runs one block if true, another if false.
3. if-else-if ladder – Checks many conditions in order.
4. switch – Chooses from many blocks based on a value.

Switch Statement – Easy Advantages and Disadvantages


Advantages:
1. Good for checking one variable against many values.
2. Easy to read and manage when you have many cases.
Disadvantages:
1. Only works with constant values (like numbers or characters).
2. Can’t check ranges (like 1–10).
3. Needs break to stop falling into the next case.
Chapter 7: Office Automation II (MS Excel 2007 or Above)
Spreadsheet Fundamentals (Easy and Short):
A spreadsheet is an electronic table made of rows and columns.
Each cell can hold data like numbers, text, or formulas.
Tools like Excel help organize, calculate, and analyse data easily.

Data Manipulation and Protection

Filtering Data (Easy and Short):


Filtering lets you show only the rows that meet certain rules.
Example: Show only employees with sales over $5000.

Data Validation (Easy and Short):


Data validation controls what can be typed in a cell.
Example: Allow only dates between January 1 and December 31.

Protecting a Worksheet (Easy and Short):


You can lock your worksheet with a password to stop others from editing it.
Go to the Review tab → Protect Sheet → Set a password.

Conditional Formatting (Easy and Short):


It changes how cells look based on their values.
Example: Show high numbers in green and low ones in red to spot trends easily.

Cybercrime (Easy and Short):


Cybercrime is the illegal use of computers or networks to commit crimes, causing harm to
individuals, businesses, or governments.
Chapter 8: Introduction to Cyber Security

Hacking:
Hacking is when someone finds and exploits weaknesses in a system to get
unauthorized access to data. It’s not always bad, but it often has negative
effects.

Cracking:
Cracking is breaking into software or security systems with malicious intent,
making it a criminal act.

White Hat Hackers:


White hat hackers are good hackers who are allowed to test and fix computer
security. They help protect systems from cybercrimes by finding problems and
fixing them, all while following the law.

Black Hat Hackers:


Black hat hackers are criminals who break into systems to steal or destroy
data. They use illegal hacking methods and cause harm.

Gray Hat Hackers:


Gray hat hackers are in between white and black hat hackers. They may act
with good or bad intentions and sometimes use their skills for personal gain.

Script Kiddies:
Script kiddies are unskilled hackers who use pre-made tools to attack systems.
They usually do it for fun or to impress others, not knowing much about
hacking.

Green Hat Hackers:


Green hat hackers are newbies eager to learn and become skilled hackers. They
ask experienced hackers questions and work to improve their skills.

Blue Hat Hackers:


Blue hat hackers are like white hat hackers but are hired by companies to test
software before release to find security issues.

Red Hat Hackers:


Red hat hackers are aggressive white hat hackers who go after black hat
hackers, stopping them with strong counterattacks. They focus on destroying the
hacker's system.
Virus:
A computer virus is a harmful program that attaches to other files. It can
spread and damage data, slow down your computer, and record your keystrokes
when you open infected files.

Worm:
A worm is a self-replicating program that spreads to other computers, usually
through a network, by exploiting security weaknesses.

Adware:
Adware displays unwanted ads on your computer, like pop-ups or full-screen
ads. Some adware can be harmless, but often it’s annoying or misleading.

Spyware:
Spyware secretly collects your personal information, like browsing history,
passwords, and payment details, and sends it to others without your knowledge.

Trojan Horses:
A Trojan is a malicious program that looks like a normal app but secretly takes
control of your computer. It tricks you into installing it, and once it's running, it
can damage or steal your data.

Infected Flash Drives/CDs:


Malware can spread through USB drives or CDs. When you plug them into a
computer, the malware installs itself and spreads to other computers.

Pirated Software:
Pirated software often has malware inside. Using pirated programs puts your
computer and personal data at risk.

Local Area Network (LAN):


Malware can also spread through networks. It attacks computers connected to
the same network without needing to be downloaded.

Authentication
Authentication is checking if you are who you say you are. For example, when
you log into a website, you use a username and password. If they match what
the website has, it lets you in. It's a way of proving you are you.

Authorization
.Authorization is the process that determines what a user can do after they are
logged in. It controls access to resources or actions based on the user's
permissions.
Multi-factor authentication (MFA) is a security method where you need to
prove who you are using two or more types of information. These types are:

1. Knowledge: Something you know (like a password).


2. Possession: Something you have (like a phone or key).
3. Inherence: Something you are (like a fingerprint or face scan).

Two-factor authentication (2FA) is a type of MFA that needs just two pieces
of information. All 2FA is MFA, but not all MFA is 2FA because MFA can use
more than two factors.

In short, MFA makes things more secure by asking for more than one proof of
your identity.

Biometric authentication is a security method that uses your unique physical


features to verify who you are. It’s used in places like airports for high security
and is easy to use.

Here are some common types:

 Facial recognition: Scans your face to match it with a stored photo.


 Fingerprint scanners: Scans your fingerprints to identify you.
 Voice recognition: Analyzes your voice to confirm it's you.
 Eye scanners: Checks the patterns in your eyes to verify your identity.

Biometrics are often used with other security methods to make access safer.

Access cards
An access card (CAC) is a card the size of a credit card with a magnetic stripe.
It’s used for ID by military, government workers, and contractors. You’ve seen
these in hotel doors or credit cards to allow access to places or systems.

You might also like