SlideShare a Scribd company logo
Prog_2 course- 2014 
2 bytes team 
Kinan keshkeh 
IT Engineering-Damascus University 
3rd year
POINTERS
Static Variables && Dynamic Variables 
Static Variables : 
var x:integer; 
The memory for this variables x still until program End , and doesn’t free even we don’t use it 
Ex: 
X 
Memory 
We determine their places at memory first of all 
value
Dynamic Variables : 
Memory 
The Heap 
X 
var x: ^integer; 
Ex: 
the address 
the address 
value 
The memory for this variables x in the Heap, we can take it or dispose it, so it can be free!! 
We determine their places at memory during the program
Why Dynamic?? 
1) better usage to memory 
2) to create advance data structure like trees , lists….atc
What is the pointer? 
The Definition 
The pointer is an address to a memory place 
Var ptr: ^Type; 
Lets Have an explication!! but…..
P1 
X 
Value.. 
P1^ 
P1 
Var p1,p2: ^Type; x :Type; 
P1^ 
P1 
P1^ 
X:=value 
P2 
xx 
P1^ 
P2 
New(p1); 
P1^:=x 
Value.. 
P2:=P1 
Value.. 
P1:=nil; 
Value.. 
+1
xx 
P1^ 
P2 
Dispose(p2); 
Value.. 
xx 
P1^ 
xx 
P2:=nil; 
Value.. 
+1
Program pointer on Soso; 
There is wrong ! 
Type 
pEmp=^Emp; 
Emp=Record 
eno:integer; ename:string[20]; 
esal:real; 
end; 
Var 
E:Emp; E1:pEmp; 
n,m,y:^integer; 
EXAMPLE:
Begin i:=5; new(y); y^:=50; write(y); write(^y); write(y^); y:=i y^:=i ; y^:=20; i:=y^; y:=0; dispose(y); y:=nil; new(m); new(y); m^:=30; y^:=80; n:=y; write(y^); write(n^); E1:=nil; new(E1); E1^:=E ; Read(E1^.Eno); Dispose(E1); End. 
false 
false 
TRUE 
NOTE: Without “ New(n)” !! 
80 80 
false 
TRUE
STACK {FILO} 
First In Last Out 
pringles
The Data 
next 
Nil 
TOP 
Stack=Record 
the Data: Type; 
next: Pstack; 
end; 
The Definition 
Pstack=^stack; 
Var 
Top: Pstack; 
D:Type; 
……….
Stack procedures : 
Push(s,ch) 
Pop(s,ch) 
S_Top(s,ch) 
Is_Empty(s) 
3) 
2) 
1) 
4)
EX: You have a string “KiKi” How to put/take it in /from the STACK ?! 
i 
next 
TOP 
K 
i 
K 
Nil
Stack=Record ch: char; next: Pstack; end; 
Type Pstack=^stack; 
Var Top: Pstack; st: string[4]; i:integer; x:char; 
BEGIN 
Readln(st); top:=nil; 
For i:=1 to (length(st) ) do 
push( top, st[i] ) ; 
While(top<>Nil) do 
begin 
Pop( top, x) ; write(x,’ ’); 
end; 
END. 
Program fifi;
PUSH 
Procedure push (var Top:Pstack; c:char); Var temp:Pstack; Begin end; 
new(temp); 
temp^.ch:=c; 
temp^.next:=top; 
top:=temp; 
i 
next 
TOP 
K 
i 
K 
Nil 
temp 
K 
TOP 
i 
TOP 
K 
TOP 
i
Stack=Record 
ch: char; 
next: Pstack; 
end; 
Type Pstack=^stack; 
Var Top: Pstack; st: string[4]; i:integer; x:char; 
BEGIN 
Readln(st); top:=nil; 
For i:=1 to (length(st) ) 
push( top, st[i] ) ; 
While(top<>Nil) do 
begin 
Pop( top, x) ; write(x,’ ’); 
end; 
END. 
Program fifi;
POP 
Procedure pop (var Top:Pstack; var c:char); 
Var temp:Pstack; 
Begin 
end; 
Dispose(temp); 
Temp:=Top; 
Top:=Top^.next ; 
C:=top^.ch; 
i 
next 
TOP 
K 
i 
K 
Nil 
The output: 
C 
i 
temp 
K 
TOP 
temp 
TOP 
i 
temp 
TOP 
K 
temp 
i 
K 
i 
K
Stack=Record ch: char; next: Pstack; end; 
Type Pstack=^stack; 
Var Top: Pstack; st: string[4]; i:integer; x:char; 
BEGIN 
Readln(st); top:=nil; 
For i:=1 to (length(st)-1) 
push( top, st[i] ) ; 
begin 
Pop( top, x) ; write(x,’ ’); 
end; 
END. 
Program fifi; 
While(top<>Nil) do
Is_Empty 
Function Is_Empty (top:Pstack):boolean begin if top =Nil then Is_Empty:=True; else Is_Empty:=false; end;
S_Top 
Function s_Top (top:Pstack): integer/…Type begin if not is_Empty(top) then s_Top :=top^.key; end; 
NOTE: Don’t write then : top:=top^.next 
Cause that function just return the element without change in stack!!
NOTE: 
You can reach to the data , at a determinate place by pointers without do pop() cause with pop() you cant restoring your ‘poped’ data .. You do: S:=top; {bring the third element 64} i:=s^.next^.next^.key; OR: S:=top; {bring the 11 element} For i:=1 to 10 do s:=s^.next; i:=s^.key 
52 
next 
TOP 
35 
64 
76 
Nil 
S 
+1
Homework: 
لديك تعبير حسابي مثلا : 
(( (1 * (3+2)) * 1) +3 ) 
المطلىب : 
حساب قيمة التعبير الحسابي وطباعتها على 
الشاشة باستخدام المكدس pop/push 
ملاحظة :مكدس واحد فقط ! 
+20 points
Group : group link Mobile phone- Kinan : 0994385748 Facebook account : kinan’s account 
2 bytes team

More Related Content

What's hot (20)

PPTX
Introduction To Stack
Education Front
 
PPTX
Stack - Data Structure
Bhavesh Sanghvi
 
PPTX
Operation on stack
chetan handa
 
PPTX
Data structure by Digvijay
Digvijay Singh Karakoti
 
PPT
skip list
iammutex
 
PPTX
Periodic pattern mining
Ashis Kumar Chanda
 
PPTX
A1 11 functions
vhiggins1
 
PDF
Data structures stacks
maamir farooq
 
PPT
Stack
srihariyenduri
 
PPTX
Stacks in Data Structure
Lovely Professional University
 
PPTX
Stack using Array
Sayantan Sur
 
PPTX
Stack_Application_Infix_Prefix.pptx
sandeep54552
 
PPTX
stacks and queues
EktaVaswani2
 
PDF
6. binary tree
Geunhyung Kim
 
PPTX
Java 8, lambdas, generics: How to survive? - NYC Java Meetup Group
Henri Tremblay
 
PPTX
Stack_Data_Structure.pptx
sandeep54552
 
PPTX
Push down automata
Ratnakar Mikkili
 
PPT
Stack queue
Harry Potter
 
Introduction To Stack
Education Front
 
Stack - Data Structure
Bhavesh Sanghvi
 
Operation on stack
chetan handa
 
Data structure by Digvijay
Digvijay Singh Karakoti
 
skip list
iammutex
 
Periodic pattern mining
Ashis Kumar Chanda
 
A1 11 functions
vhiggins1
 
Data structures stacks
maamir farooq
 
Stacks in Data Structure
Lovely Professional University
 
Stack using Array
Sayantan Sur
 
Stack_Application_Infix_Prefix.pptx
sandeep54552
 
stacks and queues
EktaVaswani2
 
6. binary tree
Geunhyung Kim
 
Java 8, lambdas, generics: How to survive? - NYC Java Meetup Group
Henri Tremblay
 
Stack_Data_Structure.pptx
sandeep54552
 
Push down automata
Ratnakar Mikkili
 
Stack queue
Harry Potter
 

Similar to 2Bytesprog2 course_2014_c5_pointers (20)

PPTX
stack (1).pptx
CrazyKiller4
 
PDF
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
pallavi953613
 
PDF
Data structure lab manual
nikshaikh786
 
PPT
Data structure lecture7
Kumar
 
PDF
data structure and algorithm.pdf
Asrinath1
 
PDF
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
PDF
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
PDF
Stack
Zaid Shabbir
 
PPTX
C# introduzione per cibo e altri usi vati
AlessandroSiroCampi
 
PPTX
Data Structures and Agorithm: DS 06 Stack.pptx
RashidFaridChishti
 
PPTX
Stack data structure
rogineojerio020496
 
ODP
Scala as a Declarative Language
vsssuresh
 
PPTX
data structure
Arvind Kumar
 
PPTX
Stacks in c++
Vineeta Garg
 
PDF
Stack concepts by Divya
Divya Kumari
 
PPTX
iPython
Aman Lalpuria
 
PDF
ds-10.pdf
VanshGarg64
 
PDF
Stacks
Sadaf Ismail
 
PDF
04 stacks
Rajan Gautam
 
stack (1).pptx
CrazyKiller4
 
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
pallavi953613
 
Data structure lab manual
nikshaikh786
 
Data structure lecture7
Kumar
 
data structure and algorithm.pdf
Asrinath1
 
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
C# introduzione per cibo e altri usi vati
AlessandroSiroCampi
 
Data Structures and Agorithm: DS 06 Stack.pptx
RashidFaridChishti
 
Stack data structure
rogineojerio020496
 
Scala as a Declarative Language
vsssuresh
 
data structure
Arvind Kumar
 
Stacks in c++
Vineeta Garg
 
Stack concepts by Divya
Divya Kumari
 
iPython
Aman Lalpuria
 
ds-10.pdf
VanshGarg64
 
Stacks
Sadaf Ismail
 
04 stacks
Rajan Gautam
 
Ad

More from kinan keshkeh (20)

PDF
10 Little Tricks to Get Your Class’s Attention (and Hold It)
kinan keshkeh
 
PDF
Simpson and lagranje dalambair math methods
kinan keshkeh
 
PDF
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
PDF
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
PDF
GeneticAlgorithms_AND_CuttingWoodAlgorithm
kinan keshkeh
 
PDF
Algorithm in discovering and correcting words errors in a dictionary or any w...
kinan keshkeh
 
PDF
2Bytesprog2 course_2014_c9_graph
kinan keshkeh
 
PDF
2Bytesprog2 course_2014_c8_units
kinan keshkeh
 
PDF
2Bytesprog2 course_2014_c6_single linked list
kinan keshkeh
 
PDF
2Bytesprog2 course_2014_c4_binaryfiles
kinan keshkeh
 
PDF
2Bytesprog2 course_2014_c3_txtfiles
kinan keshkeh
 
PDF
2Bytesprog2 course_2014_c2_records
kinan keshkeh
 
PDF
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
PDF
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
PDF
2 BytesC++ course_2014_c13_ templates
kinan keshkeh
 
PDF
2 BytesC++ course_2014_c12_ polymorphism
kinan keshkeh
 
PDF
2 BytesC++ course_2014_c11_ inheritance
kinan keshkeh
 
PDF
2 BytesC++ course_2014_c10_ separate compilation and namespaces
kinan keshkeh
 
PDF
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
kinan keshkeh
 
PDF
2 BytesC++ course_2014_c8_ strings
kinan keshkeh
 
10 Little Tricks to Get Your Class’s Attention (and Hold It)
kinan keshkeh
 
Simpson and lagranje dalambair math methods
kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
kinan keshkeh
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
kinan keshkeh
 
2Bytesprog2 course_2014_c9_graph
kinan keshkeh
 
2Bytesprog2 course_2014_c8_units
kinan keshkeh
 
2Bytesprog2 course_2014_c6_single linked list
kinan keshkeh
 
2Bytesprog2 course_2014_c4_binaryfiles
kinan keshkeh
 
2Bytesprog2 course_2014_c3_txtfiles
kinan keshkeh
 
2Bytesprog2 course_2014_c2_records
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2 BytesC++ course_2014_c13_ templates
kinan keshkeh
 
2 BytesC++ course_2014_c12_ polymorphism
kinan keshkeh
 
2 BytesC++ course_2014_c11_ inheritance
kinan keshkeh
 
2 BytesC++ course_2014_c10_ separate compilation and namespaces
kinan keshkeh
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
kinan keshkeh
 
2 BytesC++ course_2014_c8_ strings
kinan keshkeh
 
Ad

Recently uploaded (20)

PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Human Resources Information System (HRIS)
Amity University, Patna
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 

2Bytesprog2 course_2014_c5_pointers

  • 1. Prog_2 course- 2014 2 bytes team Kinan keshkeh IT Engineering-Damascus University 3rd year
  • 3. Static Variables && Dynamic Variables Static Variables : var x:integer; The memory for this variables x still until program End , and doesn’t free even we don’t use it Ex: X Memory We determine their places at memory first of all value
  • 4. Dynamic Variables : Memory The Heap X var x: ^integer; Ex: the address the address value The memory for this variables x in the Heap, we can take it or dispose it, so it can be free!! We determine their places at memory during the program
  • 5. Why Dynamic?? 1) better usage to memory 2) to create advance data structure like trees , lists….atc
  • 6. What is the pointer? The Definition The pointer is an address to a memory place Var ptr: ^Type; Lets Have an explication!! but…..
  • 7. P1 X Value.. P1^ P1 Var p1,p2: ^Type; x :Type; P1^ P1 P1^ X:=value P2 xx P1^ P2 New(p1); P1^:=x Value.. P2:=P1 Value.. P1:=nil; Value.. +1
  • 8. xx P1^ P2 Dispose(p2); Value.. xx P1^ xx P2:=nil; Value.. +1
  • 9. Program pointer on Soso; There is wrong ! Type pEmp=^Emp; Emp=Record eno:integer; ename:string[20]; esal:real; end; Var E:Emp; E1:pEmp; n,m,y:^integer; EXAMPLE:
  • 10. Begin i:=5; new(y); y^:=50; write(y); write(^y); write(y^); y:=i y^:=i ; y^:=20; i:=y^; y:=0; dispose(y); y:=nil; new(m); new(y); m^:=30; y^:=80; n:=y; write(y^); write(n^); E1:=nil; new(E1); E1^:=E ; Read(E1^.Eno); Dispose(E1); End. false false TRUE NOTE: Without “ New(n)” !! 80 80 false TRUE
  • 11. STACK {FILO} First In Last Out pringles
  • 12. The Data next Nil TOP Stack=Record the Data: Type; next: Pstack; end; The Definition Pstack=^stack; Var Top: Pstack; D:Type; ……….
  • 13. Stack procedures : Push(s,ch) Pop(s,ch) S_Top(s,ch) Is_Empty(s) 3) 2) 1) 4)
  • 14. EX: You have a string “KiKi” How to put/take it in /from the STACK ?! i next TOP K i K Nil
  • 15. Stack=Record ch: char; next: Pstack; end; Type Pstack=^stack; Var Top: Pstack; st: string[4]; i:integer; x:char; BEGIN Readln(st); top:=nil; For i:=1 to (length(st) ) do push( top, st[i] ) ; While(top<>Nil) do begin Pop( top, x) ; write(x,’ ’); end; END. Program fifi;
  • 16. PUSH Procedure push (var Top:Pstack; c:char); Var temp:Pstack; Begin end; new(temp); temp^.ch:=c; temp^.next:=top; top:=temp; i next TOP K i K Nil temp K TOP i TOP K TOP i
  • 17. Stack=Record ch: char; next: Pstack; end; Type Pstack=^stack; Var Top: Pstack; st: string[4]; i:integer; x:char; BEGIN Readln(st); top:=nil; For i:=1 to (length(st) ) push( top, st[i] ) ; While(top<>Nil) do begin Pop( top, x) ; write(x,’ ’); end; END. Program fifi;
  • 18. POP Procedure pop (var Top:Pstack; var c:char); Var temp:Pstack; Begin end; Dispose(temp); Temp:=Top; Top:=Top^.next ; C:=top^.ch; i next TOP K i K Nil The output: C i temp K TOP temp TOP i temp TOP K temp i K i K
  • 19. Stack=Record ch: char; next: Pstack; end; Type Pstack=^stack; Var Top: Pstack; st: string[4]; i:integer; x:char; BEGIN Readln(st); top:=nil; For i:=1 to (length(st)-1) push( top, st[i] ) ; begin Pop( top, x) ; write(x,’ ’); end; END. Program fifi; While(top<>Nil) do
  • 20. Is_Empty Function Is_Empty (top:Pstack):boolean begin if top =Nil then Is_Empty:=True; else Is_Empty:=false; end;
  • 21. S_Top Function s_Top (top:Pstack): integer/…Type begin if not is_Empty(top) then s_Top :=top^.key; end; NOTE: Don’t write then : top:=top^.next Cause that function just return the element without change in stack!!
  • 22. NOTE: You can reach to the data , at a determinate place by pointers without do pop() cause with pop() you cant restoring your ‘poped’ data .. You do: S:=top; {bring the third element 64} i:=s^.next^.next^.key; OR: S:=top; {bring the 11 element} For i:=1 to 10 do s:=s^.next; i:=s^.key 52 next TOP 35 64 76 Nil S +1
  • 23. Homework: لديك تعبير حسابي مثلا : (( (1 * (3+2)) * 1) +3 ) المطلىب : حساب قيمة التعبير الحسابي وطباعتها على الشاشة باستخدام المكدس pop/push ملاحظة :مكدس واحد فقط ! +20 points
  • 24. Group : group link Mobile phone- Kinan : 0994385748 Facebook account : kinan’s account 2 bytes team