dfdfdfdfdfdfddfdfdf
Programming
Fundamentals
Data Types, Identifiers, and Expressions
Dr. Ahmed Alnasheri 05/28/2025
Programming Fundamentals (Lecture Two) 1
Content
Topics to cover here:
Data types
Variables and Identifiers
Arithmetic and Logical Expressions
Programming Fundamentals (Lecture Two) 2
Data Types
A data type provides a method of modeling
or representing a particular set of values and
determines what operations can be
performed on those values.
Programming Fundamentals (Lecture Two) 3
Data Types
Programming Fundamentals (Lecture Two) 4
Data Types in The Algorithmic Language
String values (e.g. “ABC” , “computer”, “960”)
NOTE: In C++ language, some of the operations have
different symbols.
Programming Fundamentals (Lecture Two) 5
Identifiers, Locations, and Variables
Memory: It is a part of the computer
that has many locations (of fixed size)
used to store values (data) and
instructions.
Programming Fundamentals (Lecture Two) 6
Identifiers, Locations, and Variables
Identifiers (Names):
- Use meaningful identifiers (names) to represent
data in your program.
- Identifiers are used to refer to memory
locations: to store data in them or retrieve data
from them.
The rule of defining an identifier:
(1) It may contain
letters (A .. Z , a .. z ) ,
digits (0, 1, 2, …, 9), and
underscore ( _ ).
(2) It should begin with a letter.
Programming Fundamentals (Lecture Two) 7
Identifiers, Locations, and Variables
NOTES:
Some programming languages are case
sensitive. That is the uppercase identifiers are
different than lowercase identifiers (as in C++).
Inprogramming languages, some words cannot
be used as identifiers in your program. Such
words are called reserved words (or keywords)
that have special use.
Programming Fundamentals (Lecture Two) 8
Reserved words (or keywords) in c+
+
main
if
else
switch
while
do
for, ………….
Programming Fundamentals (Lecture Two) 9
Identifiers, Locations, and Variables
Examples of valid identifiers:
area , length, X , Y1, abc, d3, st_number
{ these all begin with a letter }
Examples of invalid identifiers:
2Y { begins with a digit }
Ali’s { contains the symbol ‘ }
st-age { the symbol - is not underscore }
while { it is a keyword }
ab cd { it has a space }
Programming Fundamentals (Lecture Two) 10
Identifiers, Location, and Variables
Variables:
-The name of the location is the variable name.
-The location content is the value of the variable
- You can change the content of the variable at any
time in the statements of the algorithm.
e.g.
Name of the location Inside Memory location
employee_name “Ali Ahmed”
age 35
hourly_rate 3.25
Programming Fundamentals (Lecture Two) 11
Identifiers, Location, and Variables
Constants:
- You can use a constant identifier in your
algorithm to indicate a constant data.
- You CANNOT change the content of the constant
identifier.
- Use the keyword CONST to indicate a constant
identifier.
Example:
CONST pi = 3.14
Here, pi is a constant identifier that cannot be changed
Programming Fundamentals (Lecture Two) 12
Expressions
Arithmetic Expression:
- It is composed of operands and arithmetic operations
- Arithmetic operations:
- Operands may be numbers and/or identifiers that have
numeric values
- Its result is a numeric value
EX : 3 + 4 gives 7
EX: T MOD 2 gives 0 if T is any even number, and
1 if T is any odd number
Programming Fundamentals (Lecture Two) 13
Expressions
Logical Expression:
- It is called also Boolean expression.
- It is composed from operands and operators.
- Operands are identifiers that have logical values
- Its result is a logical value (true or false) (see later).
- Operators are logical:
EX:
where A, B are defined logical
Note: In C++, there is no specific data type to represent
“true” and “false”. C uses value “0” to represent “false”, and
uses non-zero value to stand for “true”.
Programming Fundamentals (Lecture Two) 14
Expressions
Relational Expression:
- It is composed from operands and operators.
- Operands may be numbers and/or identifiers
that have numeric values
- Its result is a logical value (true or false).
- Operators are relational operators:
EX:
Programming Fundamentals (Lecture Two) 15
Expressions
NOTES
1) A relational expression may contain arithmetic
sub-expressions,
e.g. ( 3 + 7 ) < (12 * 4 )
2) A logical expression may contain relational and
arithmetic sub-expressions,
e.g.
1- x AND y AND ( a > b )
2- (2 + t ) < (6 * w ) AND ( p = q )
Programming Fundamentals (Lecture Two) 16
Operator Precedence
Expressions are evaluated according to the
precedence rule.
Precedence Rule:
- Each operator has its own precedence that
indicates the order of evaluation.
- If the expression has operators of the same
precedence, then the evaluation starts from
left of expression to the right.
Programming Fundamentals (Lecture Two) 17
Operator Precedence
Precedence Description Operator In Operator In
C++ pseudo code
Higher parentheses ( (
*, /, % *, /, MOD
Binary plus, binary +, - +, -
minus
<, <=, >, >= <, , ≤, >, ≥
Equal, not equal == , != =,≠
&& AND
|| OR
Lower Assignment =
Programming Fundamentals (Lecture Two) 18
Examples
Find the value of the following expression:
(1) 5 + 8 * 2 / 4
16
9 (This is the final result)
Programming Fundamentals (Lecture Two) 19
Examples
(2) (9 + 3) - 6 / 2 + 5
12
14 (this is the final result)
Programming Fundamentals (Lecture Two) 20
Evaluating Logical Expressions
The truth table
(1) AND table
AND True False
True True False
False False False
Programming Fundamentals (Lecture Two) 21
Evaluating Logical Expressions
(2) OR table
OR True False
True True True
False True False
(3) NOT table
NOT True False
False True
Programming Fundamentals (Lecture Two) 22
Examples on Logical
Expressions
(1) If x = True, y = False, z = False, find the
value of the expression x AND y OR z
x AND y OR z
False
False (the final result)
Programming Fundamentals (Lecture Two) 23
The End
Programming Fundamentals (Lecture Two) 24