際際滷

際際滷Share a Scribd company logo
Pointer
2
Pointer Declaration and Assignment
則 Variables and address
 覃覈襴 蟲譟
 螳 覲 覃覈襴 轟 譯殊 豺 
 覲 譯殊: Pointer

1000 a
1001
3.2
1005
4

ch, 1byte
f, 4bytes
i, 4bytes
char ch = a ;
float f = 3.2 ;
int i = 4 ;
address
3
Pointer Declaration and Assignment
則 Variables and address
 覲覿 覲 譯殊(Pointer) 詞企願鍵
char ch = a ;
float f = 3.2 ;
int i = 4 ;
printf( %d %d %dn, &a, &f, &i ) ;
&(覲企) == 覲 譯殊 
1000 a
1001
3.2
1005
4

Address
operator
4
Pointer Declaration and Assignment
則 Variables and address
 覲 譯殊(Pointer)襯 伎 覲 蠏狩蠍
char ch ;
float f ;
int i ;
*(&ch) = a ;
*(&f) = 3.2 ;
*(&i) = 4 ;
*(譯殊) (譯殊) 豺 覲襯 詩

1000 a
1001
3.2
1005
4

char ch ;
float f ;
int i ;
ch = a ;
f = 3.2 ;
i = 4 ;
Indirect
operator
5
Pointer Declaration and Assignment
則 Pointer Variable
 覲 譯殊(Pointer)襯 螳 ロ   覲
char ch = a ;
float f = 3.2 ;
int i = 4 ;
char *pch ;
float *pf ;
int *pi ;
pch = &ch ;
pf = &f ;
pi = &i ;
printf( %d %d %dn, pch, pf, pi ) ;
data_type * pointer_varaible;
char 覲 譯殊襷
ロ   覲
float 覲 譯殊襷
ロ   覲
int 覲 譯殊襷
ロ   覲
char *pch = &ch ;
float *pf = &f ;
int *pi = &i ;
6
Pointer Declaration and Assignment
則 Pointer Variable
char ch ;
float f ;
int i ;
ch = a ;
f = 3.2 ;
i = 4 ;
char ch ;
float f ;
int i ;
char *pch = &ch ;
float *pf = &f ;
int *pi = &i ;
*pch = a ;
*pf = 3.2 ;
*pi = 4 ;

1000 a
1001
3.2
1005
4
7
Pointer Declaration and Assignment
則 Pointer Variable
 覈 pointer 覲 4 bytes 蠍一企 (4 bytes machine)
 why??
char *pch ;
float *pf ;
int *pi ;
printf( %dn, sizeof(pch) ) ;
printf( %dn, sizeof(pf) ) ;
printf( %dn, sizeof(pi) ) ;
int i = 0 ;
int *pi = & i;
printf( %dn, i ) ;
printf( %dn, *pi ) ;
printf( %dn, &pi ) ;
8
Pointer Declaration and Assignment
則 Pointer Variable
 覈 pointer 覲 覲企襦 譯殊襯 螳.
int i = 0 ;
int *pi = &i;
printf( %dn, i ) ;
printf( %dn, *pi ) ;
printf( %dn, &pi ) ;
1000

1020

pi, 4 bytes
i, 4 bytes
9
Pointer Declaration and Assignment
[Ex] int *p;
int month=3;
p = &month;
pointer variable p
month memory address襯 assign
p month
3
p
1000
month
31000
譯殊襯 讌  蟆覲企る
危襯 伎 .
則 Example
10
Addressing and Dereferencing
[Ex] int a, b;
int *p;
a = 7;
b = 7;
p = &a;
printf(*p = %dn, *p);
*p = 3;
printf(a = %dn, a);
p a襯 pointing覩襦, *p == 7
p a address襯 ロ螻
朱襦, *p a襯 覩誤螻,
蟆郁記 a 伎 3朱 覲蟆
p a memory address襯 assign
*p = 7
a = 3
則 Example
11
Addressing and Dereferencing
[Ex1] int a, b;
int *p;
a = b = 7;
p = &a;
*p = 3;
p = &b;
*p = 2 * *p  a;
pa
7
b
7
p
3
a b
7
pa
3 11
b
則 Example
12
Addressing and Dereferencing
[Ex1] int x, *p;
x = 10;
*p = x;
[Ex3] int x, *p;
x = 10;
p = x;
Error!!
p 螳 譯殊伎讌  p螳 企 螻褐
refer螻 讌襯 覈襯企 
p螳 point 螻褐 x螳  覿螳
Error!!
p address襯 螳朱  point
variable企襦 int assign 覿螳
則 蠍
13
const  Pointer 覲
則 const  Pointer 覲
 p const int  覲 譯殊襯 ロ   誤 覲
 a 覲襦 螳 覦蠖  .
 p螳 螳襯危る 覲 覲企襦 p襯 牛 覲蟆暑螳
const int a = 7;
const int *p = &a; // 螳
a = 8 ; //覿螳
*p = 9 ; //覿螳
14
const  Pointer 覲
則 const  Pointer 覲
 p const int  覲 譯殊襯 ロ   誤 覲
讌襷, 朱 int  覲 譯殊襯 ロ  .
 a 朱 覲襦 螳 覦蠖  .
 p螳 螳襯危る 覲螳 朱覲願鍵 , p螳 const int 
誤磯 碁朱襦, p襯 牛 覲蟆暑螳
int a = 7;
const int *p = &a; // 螳
a = 8 ; //螳
*p = 9 ; //覿螳
15
const  Pointer 覲
則 const  Pointer 覲
 p 朱 int  覲 譯殊襯 ロ   誤 覲企
襦, 覲 a 譯殊襯 ロ  .
 襷 願 る *p=8  螳ロ螻 蟆郁記 a 螳 覦蠖 
蟆 .
const int a = 7;
int *p = &a; // 覿螳
16
const  Pointer 覲
則 const  Pointer 覲
 p const int  覲 譯殊襯 ロ   誤 覲
覩襦 覈 螳
 p const int  覲 譯殊襯 ロ  覲企襦, 豌
豐蠍壱 螳ロ讌襷, 蠏 危 豺 覿螳
const int a = 7, b = 8 ;
const int * p = &a; // 螳
p = &b; //螳
const int a = 7, b = 8 ;
const int * const p = &a; // 螳
p = &b; // 覿螳
17
れ Pointer 覲
則 れ Pointer 覲
 i int 覲
 p int 覲 譯殊襯 ロ   誤 覲
 q int 覲 譯殊襯 ロ 誤 覲 譯殊襯 
   誤 覲
 q 誤磯願鍵 覓語 蠍磯 4覦危語企(4 bytes machine)
int i = 4 ;
int *p ;
int **q ;
則 Example
18
Pointer Declaration and Assignment
[Ex] int i = 3;
int *p ;
int **q ;
p = &i ;
q = &p ;
p i
3
i
31000
p
10002000
q
20003000
q
則 Example:
 螳 螻 覃覈襴 襯 蠏碁殊
襦 蠏碁Μ.
 豕譬朱, i, j 覲 螳 朱
瑚?
 i, j, p, q 譯殊襯 螳螳 1000,
1004, 2000, 3000 企朱, p, q, r
 螳 螳螳 朱瑚?
19
Pointer Declaration and Assignment
[Ex] int i = 3, j = 2;
int *p, *q ;
int **r ;
p = &i ;
q = &j ;
r = &p ;
*p = 4 ;
*q = 5 ;
**r = 6 ;
*r = &q ;
q =&i ;
**r = 7 ;
Ad

Recommended

誤一 蠍一(1)
誤一 蠍一(1)
Hoyoung Jung
誤一蠍一 (2) - 誤 蠍1
誤一蠍一 (2) - 誤 蠍1
Hoyoung Jung
The C++ Programming Language 5 誤, 覦一, 蟲譟一牡
The C++ Programming Language 5 誤, 覦一, 蟲譟一牡
矧願
4. 誤
4. 誤
Hoyoung Jung
15 1. enumeration, typedef
15 1. enumeration, typedef
6 覦 覓語
6 覦 覓語
03. function in typescript
03. function in typescript
Han JaeYeab
07. type system
07. type system
Han JaeYeab
01. basic types
01. basic types
Han JaeYeab
メ釈過п求 危伎
メ釈過п求 危伎
Lua 覓碁
Lua 覓碁
Jaehoon Lee
覦 ろ磯(6蠍) 1
覦 ろ磯(6蠍) 1
Jina Lee
Hello python 3 襭螻 (伎 ろ磯, 覦襭)
Hello python 3 襭螻 (伎 ろ磯, 覦襭)
Cherucy
Lua 覓碁 -
Lua 覓碁 -
Jaehoon Lee
C++11
C++11
Yubin Lim
[Swift] Type inference
[Swift] Type inference
Bill Kim
Ruby - 6th (襭觜 6 覲 )
Ruby - 6th (襭觜 6 覲 )
覲 企 螻
覲 企 螻
覩殊
[Effective Modern C++] Chapter1 - item2
[Effective Modern C++] Chapter1 - item2
讌 蟾
Basic study 2谿
Basic study 2谿
Seonmun Choi
[Effective Modern C++] Chapter1 - item1
[Effective Modern C++] Chapter1 - item1
讌 蟾
Secure coding-c-preprocessor-1
Secure coding-c-preprocessor-1
Seungyong Lee
(結, C#蠍一蟲)C#語, 覈覈 語
(結, C#蠍一蟲)C#語, 覈覈 語
襴(蟲襦讌碁讌3覯豢蟲 2覿蟇磯Μ)
7蠏碁9 貊
7蠏碁9 貊
herojoon1378
遺襭
遺襭
koominsu
襭蟲譟 蠏碁 覲願
襭蟲譟 蠏碁 覲願
mil23
04 梶午п =
04 梶午п =

More Related Content

What's hot (20)

03. function in typescript
03. function in typescript
Han JaeYeab
07. type system
07. type system
Han JaeYeab
01. basic types
01. basic types
Han JaeYeab
メ釈過п求 危伎
メ釈過п求 危伎
Lua 覓碁
Lua 覓碁
Jaehoon Lee
覦 ろ磯(6蠍) 1
覦 ろ磯(6蠍) 1
Jina Lee
Hello python 3 襭螻 (伎 ろ磯, 覦襭)
Hello python 3 襭螻 (伎 ろ磯, 覦襭)
Cherucy
Lua 覓碁 -
Lua 覓碁 -
Jaehoon Lee
C++11
C++11
Yubin Lim
[Swift] Type inference
[Swift] Type inference
Bill Kim
Ruby - 6th (襭觜 6 覲 )
Ruby - 6th (襭觜 6 覲 )
覲 企 螻
覲 企 螻
覩殊
[Effective Modern C++] Chapter1 - item2
[Effective Modern C++] Chapter1 - item2
讌 蟾
Basic study 2谿
Basic study 2谿
Seonmun Choi
[Effective Modern C++] Chapter1 - item1
[Effective Modern C++] Chapter1 - item1
讌 蟾
Secure coding-c-preprocessor-1
Secure coding-c-preprocessor-1
Seungyong Lee
(結, C#蠍一蟲)C#語, 覈覈 語
(結, C#蠍一蟲)C#語, 覈覈 語
襴(蟲襦讌碁讌3覯豢蟲 2覿蟇磯Μ)
7蠏碁9 貊
7蠏碁9 貊
herojoon1378
遺襭
遺襭
koominsu
襭蟲譟 蠏碁 覲願
襭蟲譟 蠏碁 覲願
mil23
03. function in typescript
03. function in typescript
Han JaeYeab
07. type system
07. type system
Han JaeYeab
01. basic types
01. basic types
Han JaeYeab
メ釈過п求 危伎
メ釈過п求 危伎
覦 ろ磯(6蠍) 1
覦 ろ磯(6蠍) 1
Jina Lee
Hello python 3 襭螻 (伎 ろ磯, 覦襭)
Hello python 3 襭螻 (伎 ろ磯, 覦襭)
Cherucy
[Swift] Type inference
[Swift] Type inference
Bill Kim
Ruby - 6th (襭觜 6 覲 )
Ruby - 6th (襭觜 6 覲 )
覲 企 螻
覲 企 螻
覩殊
[Effective Modern C++] Chapter1 - item2
[Effective Modern C++] Chapter1 - item2
讌 蟾
Basic study 2谿
Basic study 2谿
Seonmun Choi
[Effective Modern C++] Chapter1 - item1
[Effective Modern C++] Chapter1 - item1
讌 蟾
Secure coding-c-preprocessor-1
Secure coding-c-preprocessor-1
Seungyong Lee
襭蟲譟 蠏碁 覲願
襭蟲譟 蠏碁 覲願
mil23

Similar to 9. pointer (20)

04 梶午п =
04 梶午п =
skku cp2 w4
skku cp2 w4
[170327 1譯殊姶]C語 A覦
[170327 1譯殊姶]C語 A覦
arundine
覦一願骸 誤
覦一願骸 誤
蠍 蟾
. Ruvendix
11. array & pointer
11. array & pointer
[C++ lab] 6. value,pointer,reference
[C++ lab] 6. value,pointer,reference
MinGeun Park
誤一 覦一
誤一 覦一
Kim YoSep
effective c++ chapter 3~4 襴
effective c++ chapter 3~4 襴
Injae Lee
Assembly ろ磯 2
Assembly ろ磯 2
J J
Multithread programming 20151206_讌
Multithread programming 20151206_讌
JinTaek Seo
7. variable scope rule,-storage_class
7. variable scope rule,-storage_class
More effective c++ Chap1~2
More effective c++ Chap1~2
Injae Lee
G+ Summer C Study 20130712(5殊姶)
G+ Summer C Study 20130712(5殊姶)
Jake Yoon
2 1. variables & data types
2 1. variables & data types
蟆襦蠏碁覦覓 3譯殊姶
蟆襦蠏碁覦覓 3譯殊姶
Yeonah Ki
HI-ARC PS 101
HI-ARC PS 101
Jae-yeol Lee
Lightning talk - 3
Lightning talk - 3
DonggyuKim21
Debugging with visual studio. 觜譯殊 ろるゼ 覯蟾
Debugging with visual studio. 觜譯殊 ろるゼ 覯蟾
Kiyoung Moon
04 梶午п =
04 梶午п =
skku cp2 w4
skku cp2 w4
[170327 1譯殊姶]C語 A覦
[170327 1譯殊姶]C語 A覦
arundine
覦一願骸 誤
覦一願骸 誤
蠍 蟾
11. array & pointer
11. array & pointer
[C++ lab] 6. value,pointer,reference
[C++ lab] 6. value,pointer,reference
MinGeun Park
誤一 覦一
誤一 覦一
Kim YoSep
effective c++ chapter 3~4 襴
effective c++ chapter 3~4 襴
Injae Lee
Assembly ろ磯 2
Assembly ろ磯 2
J J
Multithread programming 20151206_讌
Multithread programming 20151206_讌
JinTaek Seo
7. variable scope rule,-storage_class
7. variable scope rule,-storage_class
More effective c++ Chap1~2
More effective c++ Chap1~2
Injae Lee
G+ Summer C Study 20130712(5殊姶)
G+ Summer C Study 20130712(5殊姶)
Jake Yoon
2 1. variables & data types
2 1. variables & data types
蟆襦蠏碁覦覓 3譯殊姶
蟆襦蠏碁覦覓 3譯殊姶
Yeonah Ki
Lightning talk - 3
Lightning talk - 3
DonggyuKim21
Debugging with visual studio. 觜譯殊 ろるゼ 覯蟾
Debugging with visual studio. 觜譯殊 ろるゼ 覯蟾
Kiyoung Moon
Ad

More from (20)

15 3. modulization
15 3. modulization
15 2. arguement passing to main
15 2. arguement passing to main
14. fiile io
14. fiile io
13. structure
13. structure
12 2. dynamic allocation
12 2. dynamic allocation
12 1. multi-dimensional array
12 1. multi-dimensional array
10. pointer & function
10. pointer & function
6. function
6. function
5 2. string processing
5 2. string processing
5 1. character processing
5 1. character processing
4. loop
4. loop
3 2. if statement
3 2. if statement
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
2 3. standard io
2 3. standard io
2 2. operators
2 2. operators
Goorm ide 蟲′覯 for skku()
Goorm ide 蟲′覯 for skku()
蟲襴 蠍磯蓋 螳襭
蟲襴 蠍磯蓋 螳襭
Goorm ide 螳 殊企(蟲′ 覯)
Goorm ide 螳 殊企(蟲′ 覯)
W14 chap13
W14 chap13
13th chapter12 slide
13th chapter12 slide
15 3. modulization
15 3. modulization
15 2. arguement passing to main
15 2. arguement passing to main
14. fiile io
14. fiile io
13. structure
13. structure
12 2. dynamic allocation
12 2. dynamic allocation
12 1. multi-dimensional array
12 1. multi-dimensional array
10. pointer & function
10. pointer & function
6. function
6. function
5 2. string processing
5 2. string processing
5 1. character processing
5 1. character processing
4. loop
4. loop
3 2. if statement
3 2. if statement
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
2 3. standard io
2 3. standard io
2 2. operators
2 2. operators
Goorm ide 蟲′覯 for skku()
Goorm ide 蟲′覯 for skku()
蟲襴 蠍磯蓋 螳襭
蟲襴 蠍磯蓋 螳襭
Goorm ide 螳 殊企(蟲′ 覯)
Goorm ide 螳 殊企(蟲′ 覯)
W14 chap13
W14 chap13
13th chapter12 slide
13th chapter12 slide
Ad

9. pointer

  • 2. 2 Pointer Declaration and Assignment 則 Variables and address 覃覈襴 蟲譟 螳 覲 覃覈襴 轟 譯殊 豺 覲 譯殊: Pointer 1000 a 1001 3.2 1005 4 ch, 1byte f, 4bytes i, 4bytes char ch = a ; float f = 3.2 ; int i = 4 ; address
  • 3. 3 Pointer Declaration and Assignment 則 Variables and address 覲覿 覲 譯殊(Pointer) 詞企願鍵 char ch = a ; float f = 3.2 ; int i = 4 ; printf( %d %d %dn, &a, &f, &i ) ; &(覲企) == 覲 譯殊 1000 a 1001 3.2 1005 4 Address operator
  • 4. 4 Pointer Declaration and Assignment 則 Variables and address 覲 譯殊(Pointer)襯 伎 覲 蠏狩蠍 char ch ; float f ; int i ; *(&ch) = a ; *(&f) = 3.2 ; *(&i) = 4 ; *(譯殊) (譯殊) 豺 覲襯 詩 1000 a 1001 3.2 1005 4 char ch ; float f ; int i ; ch = a ; f = 3.2 ; i = 4 ; Indirect operator
  • 5. 5 Pointer Declaration and Assignment 則 Pointer Variable 覲 譯殊(Pointer)襯 螳 ロ 覲 char ch = a ; float f = 3.2 ; int i = 4 ; char *pch ; float *pf ; int *pi ; pch = &ch ; pf = &f ; pi = &i ; printf( %d %d %dn, pch, pf, pi ) ; data_type * pointer_varaible; char 覲 譯殊襷 ロ 覲 float 覲 譯殊襷 ロ 覲 int 覲 譯殊襷 ロ 覲 char *pch = &ch ; float *pf = &f ; int *pi = &i ;
  • 6. 6 Pointer Declaration and Assignment 則 Pointer Variable char ch ; float f ; int i ; ch = a ; f = 3.2 ; i = 4 ; char ch ; float f ; int i ; char *pch = &ch ; float *pf = &f ; int *pi = &i ; *pch = a ; *pf = 3.2 ; *pi = 4 ; 1000 a 1001 3.2 1005 4
  • 7. 7 Pointer Declaration and Assignment 則 Pointer Variable 覈 pointer 覲 4 bytes 蠍一企 (4 bytes machine) why?? char *pch ; float *pf ; int *pi ; printf( %dn, sizeof(pch) ) ; printf( %dn, sizeof(pf) ) ; printf( %dn, sizeof(pi) ) ; int i = 0 ; int *pi = & i; printf( %dn, i ) ; printf( %dn, *pi ) ; printf( %dn, &pi ) ;
  • 8. 8 Pointer Declaration and Assignment 則 Pointer Variable 覈 pointer 覲 覲企襦 譯殊襯 螳. int i = 0 ; int *pi = &i; printf( %dn, i ) ; printf( %dn, *pi ) ; printf( %dn, &pi ) ; 1000 1020 pi, 4 bytes i, 4 bytes
  • 9. 9 Pointer Declaration and Assignment [Ex] int *p; int month=3; p = &month; pointer variable p month memory address襯 assign p month 3 p 1000 month 31000 譯殊襯 讌 蟆覲企る 危襯 伎 . 則 Example
  • 10. 10 Addressing and Dereferencing [Ex] int a, b; int *p; a = 7; b = 7; p = &a; printf(*p = %dn, *p); *p = 3; printf(a = %dn, a); p a襯 pointing覩襦, *p == 7 p a address襯 ロ螻 朱襦, *p a襯 覩誤螻, 蟆郁記 a 伎 3朱 覲蟆 p a memory address襯 assign *p = 7 a = 3 則 Example
  • 11. 11 Addressing and Dereferencing [Ex1] int a, b; int *p; a = b = 7; p = &a; *p = 3; p = &b; *p = 2 * *p a; pa 7 b 7 p 3 a b 7 pa 3 11 b 則 Example
  • 12. 12 Addressing and Dereferencing [Ex1] int x, *p; x = 10; *p = x; [Ex3] int x, *p; x = 10; p = x; Error!! p 螳 譯殊伎讌 p螳 企 螻褐 refer螻 讌襯 覈襯企 p螳 point 螻褐 x螳 覿螳 Error!! p address襯 螳朱 point variable企襦 int assign 覿螳 則 蠍
  • 13. 13 const Pointer 覲 則 const Pointer 覲 p const int 覲 譯殊襯 ロ 誤 覲 a 覲襦 螳 覦蠖 . p螳 螳襯危る 覲 覲企襦 p襯 牛 覲蟆暑螳 const int a = 7; const int *p = &a; // 螳 a = 8 ; //覿螳 *p = 9 ; //覿螳
  • 14. 14 const Pointer 覲 則 const Pointer 覲 p const int 覲 譯殊襯 ロ 誤 覲 讌襷, 朱 int 覲 譯殊襯 ロ . a 朱 覲襦 螳 覦蠖 . p螳 螳襯危る 覲螳 朱覲願鍵 , p螳 const int 誤磯 碁朱襦, p襯 牛 覲蟆暑螳 int a = 7; const int *p = &a; // 螳 a = 8 ; //螳 *p = 9 ; //覿螳
  • 15. 15 const Pointer 覲 則 const Pointer 覲 p 朱 int 覲 譯殊襯 ロ 誤 覲企 襦, 覲 a 譯殊襯 ロ . 襷 願 る *p=8 螳ロ螻 蟆郁記 a 螳 覦蠖 蟆 . const int a = 7; int *p = &a; // 覿螳
  • 16. 16 const Pointer 覲 則 const Pointer 覲 p const int 覲 譯殊襯 ロ 誤 覲 覩襦 覈 螳 p const int 覲 譯殊襯 ロ 覲企襦, 豌 豐蠍壱 螳ロ讌襷, 蠏 危 豺 覿螳 const int a = 7, b = 8 ; const int * p = &a; // 螳 p = &b; //螳 const int a = 7, b = 8 ; const int * const p = &a; // 螳 p = &b; // 覿螳
  • 17. 17 れ Pointer 覲 則 れ Pointer 覲 i int 覲 p int 覲 譯殊襯 ロ 誤 覲 q int 覲 譯殊襯 ロ 誤 覲 譯殊襯 誤 覲 q 誤磯願鍵 覓語 蠍磯 4覦危語企(4 bytes machine) int i = 4 ; int *p ; int **q ;
  • 18. 則 Example 18 Pointer Declaration and Assignment [Ex] int i = 3; int *p ; int **q ; p = &i ; q = &p ; p i 3 i 31000 p 10002000 q 20003000 q
  • 19. 則 Example: 螳 螻 覃覈襴 襯 蠏碁殊 襦 蠏碁Μ. 豕譬朱, i, j 覲 螳 朱 瑚? i, j, p, q 譯殊襯 螳螳 1000, 1004, 2000, 3000 企朱, p, q, r 螳 螳螳 朱瑚? 19 Pointer Declaration and Assignment [Ex] int i = 3, j = 2; int *p, *q ; int **r ; p = &i ; q = &j ; r = &p ; *p = 4 ; *q = 5 ; **r = 6 ; *r = &q ; q =&i ; **r = 7 ;