SlideShare a Scribd company logo
1 of 33
Download to read offline
เปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
Advance Computer Programming
รหัสวิชา 32090207
อ. กิตตินันท์ น้1อยมณี 1
เนื้อหา
1. การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
2. Simple Linked List
อ. กิตตินันท์ น้1อยมณี 2
การเปลี่ยนตําแหน่งการชี้
ของพอยน์เตอร์
อ. กิตตินันท์ น้3อยมณี 3
การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
• เพื่อให้เข้าใจ Function ที่สามารถเปลี่ยน Pointer ให้ไปชี้ที่อื่นๆ
ได้
• เพื่อให้เข้าใจการนําข้อมูลที่ Pointer ชี้อยู่ภายนอก มาใช้งาน
ภายใน Function ได้
• เข้าใจการใช้ Pointer ชี้ข้อมูล และ Pointer ที่ชี้ Pointer ได้
อ. กิตตินันท์ น้1อยมณี 4
การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
อ. กิตตินันท์ น้1อยมณี 5
ตัวอย่างที่ 1: Pointer 1 ระดับ
การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
อ. กิตตินันท์ น้1อยมณี 6
ตัวอย่างที่ 1: Pointer 1 ระดับ
• Pointer 1 ระดับถูกประกาศใน main
• แต่ Function ย่อยสามารถเปลี่ยนที่ชี้ของ Pointer ให้ไปชี้ยังที่
อื่นได้ด้วย
• ในการนํามาใช้งาน หลังจากที่ Function ย่อยเปลี่ยนที่ชี้ของ
Pointer เสร็จแล้ว ใน main ก็สามารถเรียกใช้ Pointer นั้นๆ ได้
เลย (เพราะเปลี่ยนที่ชี้แล้ว)
การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
อ. กิตตินันท์ น้1อยมณี 7
ตัวอย่างที่ 1: Pointer 1 ระดับ
ตอนแรกยังไม่ได้ชี้อะไร
การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
อ. กิตตินันท์ น้1อยมณี 8
ตัวอย่างที่ 1: Pointer 1 ระดับ
ส่ง Pointer เปล่าๆ เพื่อให้
ไปกําหนดตําแหน่งการชี้ที่
Function แทน
การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
อ. กิตตินันท์ น้1อยมณี 9
ตัวอย่างที่ 1: Pointer 1 ระดับ กําหนดจุดชี้ให้กับ *a เป็น
ที่เรียบร้อย โดยให้ชี้ไปยัง
ค่าของ b ดังนั้น a จึงเก็บ
Address ของ b เอาไว้
การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
อ. กิตตินันท์ น้1อยมณี 10
ตัวอย่างที่ 1: Pointer 1 ระดับ
เมื่อออกจาก Function ก็
พบว่าค่าของ *a ได้ถูก
กําหนดจุดชี้เป็นที่
เรียบร้อยแล้ว
การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
อ. กิตตินันท์ น้1อยมณี 11
ตัวอย่างที่ 2: Pointer 2 ระดับ
การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
อ. กิตตินันท์ น้1อยมณี 12
ตัวอย่างที่ 2: Pointer 2 ระดับ
การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
อ. กิตตินันท์ น้1อยมณี 13
ตัวอย่างที่ 2: Pointer 2 ระดับ
• Pointer 2 ระดับถูกประกาศใน main
• แต่ Function ย่อยสามารถเปลี่ยนที่ชี้ของ Pointer ให้ไปชี้ยังที่
อื่นได้ด้วย
• ในการนํามาใช้งาน หลักจากที่ Function ย่อยเปลี่ยนที่ชี้ของ
Pointer เสร็จแล้ว ใน main ก็สามารถเรียกใช้ Pointer นั้นๆ ได้
เลย (เพราะเปลี่ยนที่ชี้แล้ว)
การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
อ. กิตตินันท์ น้1อยมณี 14
ตัวอย่างที่ 2: Pointer 2 ระดับ
• ข้อสังเกตคือ การชี้ไปยัง Pointer อีกตัวนึง ตัวที่จะชี้จะต้องมี
ศักย์หรือระดับของ Pointer มากกว่าตัวชี้อยู่ 1 ตัวเสมอ
การเปลี่ยนตําแหน่งการชี้ของพอยน์เตอร์
อ. กิตตินันท์ น้1อยมณี 15
ตัวอย่างที่ 2: Pointer 2 ระดับ
Simple Linked List
อ. กิตตินันท์ น้16อยมณี 16
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 17
 one  two  three  four 
start data next data next data next data next

data next
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 18
 one  two  three  four 

now1
start data next data next data next data next
หมายเหตุ: now1 ใช้ชี้ Data
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 19
 one  two  three  four 

now2
start data next data next data next data next
หมายเหตุ: now2 ใช้ชี้ตัวถัดไป (Next)
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 20
 one  two  three  four 


now1
now2
start data next data next data next data next
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 21
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 22
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 23
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 24
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 25

start
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 26
 one 
start data next
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 27
 one  two 
start data next data next
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 28
 one  two  three 
start data next data next data next
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 29
 one  two  three  four 
start data next data next data next data next
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 30
 one  two  three  four 

now1
start data next data next data next data next
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 31
 one  two  three  four 

now1
start data next data next data next data next

now2
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 32
Simple Linked List
อ. กิตตินันท์ น้1อยมณี 33
• นั่นคือ ถ้า Parameter เป็น Pointer ระดับเดียวกัน Pointer
ภายนอก Function จะไม่สามารถเปลี่ยนที่ชี้ของภายนอกได้
ดังนั้น Parameter จะต้องเป็น Pointer ที่สูงกว่า 1 ระดับ
• ควรระวังเรื่องลําดับความสําคัญของเครื่องหมาย โดยใช้ วงเล็บ
“(” และ “)” ครอบเอาไว้ให้ถูกต้อง

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

(Big One) C Language - 04 เปลี่ยนตำแหน่งการชี้ของpointer