This document discusses structures in C programming. It explains that structures can contain elements of different data types, accessed by name, unlike arrays where all elements must be of the same type and accessed by index. It provides examples of declaring a structure type with members, defining structure variables, accessing members using the dot operator, passing structures to functions, and initializing an array of structures.
The document discusses call-by-value in function invocation in C. When a function is called, only the values of the arguments are passed to the function, not the variables themselves. So any changes made to the parameters inside the function are not reflected in the calling function. This causes an issue when trying to swap variables by passing them to a Swap function.
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
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 ;