Introduction to ComputerSystems
Variables and Arithmetic Expressions
Symbolic Constants and Scope
Operators in C
Type Conversions
Table of
Contents
Control Flow Statements
01.
02.
03.
04.
05.
06.
Central Processing Unit(CPU),
Memory (RAM), Storage (Hard drive,
SSD), Input/Output devices
(Keyboard, Mouse, Monitor).
Hardware Components
The CPU executes instructions provided
by the software, using memory to store
data and interacting with I/O devices.
How Hardware and Software
Interact
Operating System (Windows, macOS,
Linux), Applications (Word
processors, Web browsers,
Compilers).
Software Components
What is a Computer?
5.
Bits and Bytes
Computersuse binary (0s and 1s) to
represent data.
Binary Representation
A byte consists of 8 bits and is a fundamental
unit of data; Larger units: Kilobyte (KB),
Megabyte (MB), Gigabyte (GB), Terabyte (TB).
Bytes and Data Sizes
6.
01
Compilers translate high-levelcode into machine code;
Interpreters execute high-level code line by line.
Compilers and Interpreters
02
High-level languages (C, Java, Python) are
easier for humans to read and write; Low-
level languages (Assembly) are closer to
machine code.
High-Level vs. Low-Level Languages
03 C is a powerful, efficient, and versatile
language widely used in system
programming and embedded systems;
Forms the basis for many other
languages.
Why C?
Introduction to Programming Languages
Declaring Variables
Specify thedata type (e.g., int, float, char) and
name of the variable; Example: `int age;`
Definition of a Variable
A variable is a named storage location in memory
that can hold a value; Used to store data that can be
modified during program execution.
Initializing Variables
Assign an initial value to a variable when it is
declared; Example: `int age = 20;`
What is a Variable?
9.
Data Types andSizes
Character Type
`char` (typically 1 byte), used to store single
characters; Example: `char grade = 'A';`
Floating-Point Types
`float` (typically 4 bytes), `double` (typically 8 bytes);
Used to store decimal numbers.
Integer Types
`int` (typically 4 bytes), `short` (typically 2 bytes),
`long` (typically 8 bytes); `unsigned int` for non-
negative integers.
10.
Arithmetic Operators
Basic Operators
Addition(+), Subtraction (-),
Multiplication (), Division (/),
Modulus (%).
01
Operator Precedence
Multiplication and division have
higher precedence than
addition and subtraction; Use
parentheses to control the
order of evaluation.
02
Examples of Arithmetic
Expressions
`int x = 10 + 5 2; // x = 20`; `float
y = (10 + 5) / 2.0; // y = 7.5`
03
What is aSymbolic Constant?
Definition of a
Symbolic Constant
01
A symbolic constant is a
name given to a value that
cannot be changed during
program execution; Makes
code more readable and
maintainable.
Using `#define`
02
The `#define` preprocessor
directive is used to define
symbolic constants;
Example: `#define PI
3.14159`
Using `const` Keyword
03
The `const` keyword can also
be used to declare
constants; Example: `const
int MAX_VALUE = 100;`
13.
Scope of Variables
LocalVariables
Declared inside a function and are
only accessible within that function.
Global Variables
Declared outside any function and
are accessible throughout the
entire program; Use with caution,
as they can make code harder to
maintain.
Block Scope
Variables declared inside a block
(e.g., inside an `if` statement or
loop) are only accessible within that
block.
14.
Example: Calculating CircleArea
Code Snippet
#include <stdio.h>
#define PI 3.14159
int main() {
float radius = 5.0;
float area = PI *
radius * radius;
printf("Area = %f
n", area);
return 0;
}
15.
Example: Calculating CircleArea
Uses symbolic constant PI and local variable radius to
calculate and print the area of a circle.
Explanation
Increment and DecrementOperators
Examples
Postfix and Prefix Operators
`x++` (postfix): use the current value of x, then
increment; `++x` (prefix): increment x, then use
the new value.
18.
Increment and DecrementOperators
Examples
int x = 5;
printf("%dn", x++); // Output:
5, x becomes 6
printf("%dn", ++x); // Output:
7, x becomes 7
19.
Bitwise Operators
AND, OR,XOR, NOT
`&` (AND), `|` (OR), `^` (XOR), `~` (NOT); Used for
manipulating individual bits of an integer.
Shift Operators
`<<` (left shift), `>>` (right shift); Used for shifting bits
to the left or right.
Examples
20.
Bitwise Operators
Examples
unsigned intx = 5; // 00000101
in binary
unsigned int y = 3; // 00000011
in binary
printf("%un", x & y); // Output:
1 (00000001)
printf("%un", x << 1); //
Output: 10 (00001010)
21.
`=` assigns thevalue on the right to
the variable on the left; Example:
`int x = 10;`
Simple Assignment
01
`+=`, `-=`, `=`, `/=`, `%=`; Example: `x
+= 5` is equivalent to `x = x + 5`
Compound Assignment
02
Examples
03
Assignment Operators and Expressions
22.
Assignment Operators andExpressions
Examples
int x = 10;
x += 5; // x
is now 15
x *= 2; // x
is now 30
Operator Precedence andOrder of Evaluation
Precedence Table
Operators are evaluated based on
their precedence (e.g., multiplication
before addition); Use parentheses to
override precedence.
Examples
01
02
03
Associativity
If operators have the same
precedence, associativity determines
the order of evaluation (left-to-right
or right-to-left).
26.
Operator Precedence andOrder of Evaluation
Examples
int x = 2 + 3 * 4; // x = 14
(multiplication first)
int y = (2 + 3) * 4; // y = 20
(parentheses first)
Implicit Type Conversion
Automaticconversion of data types by
the compiler; Usually done when
performing operations between different
data types.
What is Implicit Type Conversion?
Examples
Implicit Type Conversion
Lower-rankedtypes are promoted to higher-ranked
types (e.g., `int` to `float`, `float` to `double`).
Rules for Implicit Conversion
31.
Explicit Type Conversion(Casting)
What is Explicit Type Conversion?
Manually converting a value from one type to another
using the cast operator.
Syntax
`(type) expression`; Example: `(int) 3.14159`
Examples
32.
Explicit Type Conversion(Casting)
Examples
float x = 3.14159;
int y = (int) x; // y
= 3 (truncation)
printf("%dn", y);
33.
Data Type Sizes
The`sizeof` operator returns the size (in
bytes) of a data type or variable.
`sizeof` Operator
Examples
34.
Data Type Sizes
Examples
#include<stdio.h>
int main() {
printf("Size of int: %lu bytesn",
sizeof(int));
printf("Size of float: %lu bytes
n", sizeof(float));
printf("Size of double: %lu bytes
n", sizeof(double));
return 0;
}
`if` and `if-else`Statements
Basic `if` Statement
Executes a block of code if a
condition is true; `if (condition) { /
code / }`
`if-else` Statement
Executes one block of code if a condition is
true and another block if it is false; `if
(condition) { / code if true / } else { / code if
false / }`
Examples
37.
`if` and `if-else`Statements
Examples
int age =
20;
if (age >=
18) {
printf("Adul
tn");
} else {
printf("Mino
rn");
}
`for` Loop
Provides amore structured way to write
loops with initialization, condition, and
increment/decrement in one line; `for
(initialization; condition;
increment/decrement) { / code / }`
Basic `for` Loop
Examples
Similar to `while`loop, but the code block is executed
at least once because the condition is checked at the
end; `do { / code / } while (condition);`
Basic `do-while` Loop
Examples
`do-while` Loop
`break` Statement
Terminates theloop or
`switch` statement
immediately.
`continue`
Statement
Skips the rest of the
current iteration and
continues with the next
iteration.
`goto` Statement
Transfers control to a
labeled statement; Use
with caution.
Examples
`break`, `continue`, and `goto`
51.
`break`, `continue`, and`goto`
Examples
for (int i = 0; i < 10; i++) {
if (i == 5) break; // Exit
loop
if (i % 2 == 0) continue; //
Skip even numbers
printf("%dn", i);
}
Importance of CProgramming
Highlight the significance of C in various
fields.
Recap
Briefly review the main topics covered
(variables, operators, control flow, loops).
Summary of Key Concepts
54.
Next Steps
Recommend books,online courses, and
websites for further study.
Further Learning Resources
Encourage students to practice coding to
reinforce their understanding.
Practice Exercises
55.
Q & A
Addressquestions and clarify any doubts about the
topics covered.
Open the floor to Questions