DSA-02-Variables_Pointers_Arrays
DSA-02-Variables_Pointers_Arrays
Mohammad GANJTABESH
mgtabesh@ut.ac.ir
I Built-in types ÷
float
identical Lint
char
I Arrays ÷ collection of data with , ,
- - .
)
I Struct and class : collection of type
data (
.
1 / 11
Memory management
• How different types of data are stored and manipulated in memory?
• The role of operating system all the resources
÷
managing etc )
( memory , ,
.
process
Memory management:
• Segmentation
• Paging
Memory
☐
2 / 11
Memory management: segmentation
File system
int mainly Machine →
int x ; code .
\main.enI
char c ; file
(0/1)
Cin >> xD C 's
process main
Contax Kc ;
}
return to ) ;
ode segment
Data
/
¥
Heap
Segment .
3 / 11
mmmm
6/5
Memory management: paging
Mem
t.im#iE*r
.
} code , A , P#3
Page
512 B
4 / 11
Memiadd allocated
-
Variables -
(o
( ooo
o I
to
my
-
2
process
I 00
{
10 03
-
• Variables’ attributes: 2L _
too 4
c { -
'
5 / 11
Pointers Too
[
• A place-holder in memory for storing memory address! 102
µ ,
my µ , ,
; ;¥÷:
" *
p=&x :
cart Kxk*pK&p ; '
, I
5
?
"° I
cant KP
=
¥ man .
6 / 11
type X-P 's
1/5/73 :
Arrays int sets]={
Ptt 's = p= ptsizeofctype) int x-p =&x[is ; Ptt 's
int Aef - x ;
: ¥=÷÷:÷
• Random access (constant time)
• Fixed size (static memory allocation)
• Consecutive memory bytes are allocated to arrays
• Number of elements in an array could be specified at
I compile time (static memory allocation)
I run time (dynamic memory allocation)
÷÷¥É |¥≠
*
*
91¥
a
/☒ 7 / 11
them
Multi-dimensional arrays
↑
A- [0,3]
Column major
-
-
-
-
"""
mxn
"
v.
£ columns
Now - major
,
µ , µ, , ,.gg, , , ,
,,÷,
8 / 11
Dynamic memory allocation
• Should be asked from the operating system to do the memory allocation
at run-time.
• Pointers are usually required.
at run-time .
could be specified
int x-p ;
(int))
A) maltoccnxsizeof
;
p - (int
↓
allocation
memory
.
'
int with
'
points to an
array of type n
element,
9 / 11
Struct and Class
• To define a new type containing different types of data (fields).
• User-defined type.
ɧ÷ !
struct students
}
name
a.
int ID ;
4 bytes
÷
}
student x ;
struct *p=&n ;
10 / 11
?⃝
Abstract Data Type (ADT)
Definition
A class of objects whose logical behavior is defined by a set of values and a
set of operations.
-
Constructors -
-
Destructions .
the state
- Transformers -
clear
of
change /modify the ADT .
state of ADT
-
Observers :
allow read-only
access to the state
of ADF
-
Iterators :
11 / 11