งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

หน่วยที่ แอเรย์และพอยน์เตอร์

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "หน่วยที่ แอเรย์และพอยน์เตอร์"— ใบสำเนางานนำเสนอ:

1 หน่วยที่ 3 แอเรย์และพอยน์เตอร์

2 ข้อมูลดิจิตอล บิท (Bit)
หน่วยความจำที่ย่อยที่สุดของคอมพิวเตอร์คือการ เปิด/ปิด (‘On’ /‘Off ’ ) มักจะเขียน 1 แทน ‘On’ และ 0 แทน ‘Off’ เป็นหน่วยที่เล็กที่สุดของข้อมูลในคอมพิวเตอร์ที่เรียกว่า “บิท” (Bit)

3 ข้อมูลดิจิตอล ไบท์ (Byte) ข้อมูลในคอมพิวเตอร์จะถูกมองทีละ 8 บิท
เช่น ‘ ’ เป็นต้น ข้อมูลที่เรียงกัน 8 บิทนี้ เรียกว่า ไบท์ (Byte)

4 ข้อมูลดิจิตอล ข้อมูลชิ้นหนึ่งอาจประกอบด้วยหลายๆไบท์
ตัวอย่างเช่นข้อมูลไบท์หนึ่ง มีค่า ‘ ’ อาจมองว่าเป็นจำนวน 6 หรือเป็นตัวอักษร ‘B’ ก็ได้

5 ตัวเลขและการคำนวณ ตัวเลขฐานสอง (Binary) ประกอบด้วยตัวเลข 0,1
ตัวเลขฐานสิบ (Decimal) ประกอบด้วยตัวเลข 0,1,2,3,4,5,6,7,8,9 ตัวเลขฐานแปด (Octal) ประกอบด้วยตัวเลข 0,1,2,3,4,5,6,7 ตัวเลขฐานสิบหก (Hexadecimal) ประกอบด้วยตัวเลข 0,1,2,3,4,5,6,7, 8, 9, A, B, C, D, E, F

6 ตัวเลขฐานสอง ตัวเลขฐานสองจำนวนหนึ่งไบต์
แทนค่า 0 ถึง 255 ฐานสิบ แสดงให้เห็นดังนี้ ฐานสิบ ฐานสอง 1 2 3 4 5 ... . 255

7 การแปลงตัวเลขฐานสองเป็นฐานสิบ
เอาตัวเลขฐานสองแต่ละหลักคูณด้วย 2หลัก แล้วเอาทั้งหมดมาบวกกัน เช่น ( ) 2 = (1 * 27) + (0 * 26) + (0 * 25) + (1 * 24) + (0 * 23) + (1 * 22) + (1 * 21) + (0 * 20) = =

8 การแปลงตัวเลขฐานสิบเป็นฐานสอง
เอาตัวเลขฐานสิบหารด้วย 2 ลงไปเรื่อยๆ แล้วเก็บเศษมาต่อกันย้อนหลัง เช่น 15010 / 2 = เศษ 0 7510 / = เศษ 1 3710 / = เศษ 1 1810 / = เศษ 0 910 / = เศษ 1 410 / 2 = เศษ 0 210 / 2 = เศษ 0 110 / 2 = เศษ 1 ดังนั้น =

9 ตัวเลขฐาน 16 ตัวเลขฐาน 16 ประกอบด้วยตัวเลข 0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F โดย A – F แทนค่า 10 – 15 ตัวเลขฐาน 16 หนึ่งตัวใช้แทนเลขฐานสอง 4 บิต ฐาน 16 ฐาน 2 ฐาน 16 ฐาน 2 1 2 3 4 5 6 7 8 1 9 A B C D E F

10 ตัวเลขฐาน 16 และฐาน 2 ตัวเลขฐาน 16 สองตัวใช้แทนเลขฐานสอง 1 ไบต์ ฐาน 16
ตัวเลขฐาน 16 สองตัวใช้แทนเลขฐานสอง 1 ไบต์ ฐาน 16 ฐาน 2 30 AE F5

11 การแทนค่าตัวอักษร ในการแทนค่าตัวอักษรแต่ละตัวด้วยหนึ่งไบท์ ซึ่งกำหนดไว้ว่า ‘A’ มีรหัสเป็น ‘ ’ ‘B’ มีรหัสเป็น ‘ ’ ไปเรื่อยๆ ถ้าคุณชื่อว่า ‘SAM’ ข้อมูลสามไบท์ที่ใช้แทนชื่อของคุณในคอมพิวเตอร์ก็จะเป็น , , รหัสนี้มีชื่อเรียกว่า American Standard Code for Information หรือ ASCII

12 รหัส ASCII HEX DEC ASCII 00 NULL 20 32 (SP) 40 64 @ 60 96 ` 01 1 SOH
NULL 20 32 (SP)  40 64 60 96 01 1 SOH 21 33 ! 41 65 A 61 97 a 02 2 STX 22 34 " 42 66 B 62 98 b 03 3 ETX 23 35 # 43 67 C 63 99 c 04 4 EOT 24 36 $ 44 68 D 100 d 05 5 ENQ 25 37 % 45 69 E 101 e 06 6 ACK 26 38 & 46 70 F 102 f 07 7 BEL 27 39 ' 47 71 G 103 g 08 8 BS 28 ( 48 72 H 104 h 09 9 HT 29 41 ) 49 73 I 69 105 i 0A 10 LF 2A 42 * 4A 74 J 6A 106 j 0B 11 VT 2B 43 + 4B 75 K 6B 107 k 0C 12 FF 2C 44 , 4C 76 L 6C 108 l 0D 13 CR 2D 45 - 4D 77 M 6D 109 m 0E 14 SO 2E 46 . 4E 78 N 6E 110 n 0F 15 SI 2F 47 / 4F 79 O 6F 111 o 16 DLE 30 48 50 80 P 70 112 p 17 DC1 31 1 51 81 Q 71 113 q 18 DC2 32 2 52 82 R 72 114 r

13 หน่วยความจำของคอมพิวเตอร์ จะแบ่งออกเป็นช่องๆ
10 A100 A101 K A102 5.7 A103 A104 A105 A106 A A107 B A108 \0 A109 A110 A111 A112 A113 A114 A115 A116 A117 . A118 A119 หน่วยความจำของคอมพิวเตอร์ จะแบ่งออกเป็นช่องๆ แต่ละช่องจะมีหมายเลขประจำช่อง เรียกว่า Address (เปรียบเหมือนบ้านเลขที่) แต่ละช่องจะเก็บข้อมูลได้หนึ่งไบต์ ข้อมูลหนึ่งค่าอาจเก็บข้อมูล หลายไบต์

14 การเก็บข้อมูลชนิดต่างๆในหน่วยความจำ
int long int char float double ตัวเลขจำนวนเต็ม ตัวอักษร เลขทศนิยม 2 ไบต์ 4 ไบต์ 1 ไบต์ 8 ไบต์

15 ความหมายของพอยน์เตอร์
พอยน์เตอร์ ใช้หน่วยความจำ 4 ไบต์ เก็บข้อมูลประเภทที่ใช้ชี้ตำแหน่งของหน่วยความจำ (memory address) ซึ่งเก็บค่าของตัวแปรตัวอื่นอยู่

16 การประกาศตัวแปรพอยน์เตอร์
i 10 A100 A101 c ‘K’ A102 e 5.7 A103 A104 A105 A106 mc[0] ‘A’ A107 mc[1] ‘B’ A108 mc[2] ‘\0’ A109 ca A110 A111 A112 A113 ia A114 A115 A116 A117 . A118 A119 การประกาศตัวแปรพอยน์เตอร์ ชนิด *ชื่อตัวแปรพอยน์เตอร์; int i=10; char c='K'; float e=5.7; char mc[3]="AB"; char *ca; int *ia;

17 การกำหนดค่าให้พอยน์เตอร์
ค่าที่จะกำหนดให้กับพอยน์เตอร์ ควรเป็นค่าแอดเดรสของตัวแปรโดยใช้เครื่องหมาย & ca = &c; ia = &i;

18 การใช้พอยน์เตอร์ การใช้ข้อมูลในแอดเดรสที่พอยน์เตอร์ชี้อยู่ ทำได้โดยใช้เครื่องหมายสตาร์ * ตัวอย่างเช่น จากคำสั่งเหล่านี้ ia = &i; /* กำหนดให้ ia ชี้ไปยังตำแหน่งของ i */ printf("Value of i is %d\n", i); /* สั่งให้พิมพ์ค่าของ i */ printf("Value of ia is %d\n", ia); /* สั่งให้พิมพ์ค่าของ ia ซึ่งชี้ตำแหน่งของ i */ printf("Value pointed by ia is %d\n", *ia); /* สั่งให้พิมพ์ค่าในตำแหน่งที่ ia ชี้อยู่ */ สิ่งที่พิมพ์ออกมาจะเป็น Value of i is 10 Value of ia is A100 Value pointed by ia is 10

19 สิ่งที่พิมพ์ออกมาจะเป็น
จากคำสั่งเหล่านี้ ca = &c; /* กำหนดให้ ca ชี้ตำแหน่งของ c */ printf(“Value of c is %c”, c); /* พิมพ์ค่าของ c */ printf(“Value of ca is %d”, ca); /* พิมพ์ค่าของ ca ซึ่งชี้ตำแหน่งของ c */ printf(“Value pointed by ca is %c”, *ca); /*พิมพ์ค่าในตำแหน่งที่ ca ชี้ */ สิ่งที่พิมพ์ออกมาจะเป็น Value of c is K Value of ca is A102 Value pointed by ca is K

20 } /* A program to show the use of pointers */ #include <stdio.h>
main() { int i=10; /* i is an integer */ char c='K'; /* c is a character */ float e=5.7; /* e is a float number */ char me[3]="AB"; /* me is an array of char */ char *ca; /* ca is a pointer to char */ int *ia; /* is is a pointer to int */ ia = &i; printf("Value of i is %d\n", i); printf("Value of ia is %p\n", ia); printf("Value pointed by ia is %d\n", *ia); ca = &c; printf("Value of c is %c\n", c); printf("Value of ca is %d\n", ca); printf("Value pointed by ca is %c\n", *ca); } Value of i is 10 Value of ia is 100 Value pointed by ia is 10 Value of c is K Value of ca is 102 Value pointed by ca is K

21 พอยน์เตอร์กับแอเรย์ ชื่อแอเรย์นั้นจะถือว่าเป็นแอดเดรสอยู่แล้ว
char mc[3]= "AB"; /* ตัวแปร mc เป็น array ของ char */ printf("%c", mc[0]); /* พิมพ์ค่าของ mc[0] */ printf("%d", mc); /* พิมพ์ค่าของ mc ซึ่งคือ address ของตำแหน่งแรก ของแอเรย์ */ printf("%d", &mc[0]); /* พิมพ์ค่าของ address ของตำแหน่งแรกของแอเรย์ */ printf("%c", *mc); /* พิมพ์ค่าในตำแหน่งที่ mc ชี้อยู่*/ A 107

22 } /* A program to show the use of pointers */ #include <stdio.h>
main() { int i=10; char c='A'; float e=5.7; char mc[3]="AB"; char *ca; int *ia; printf("Value of mc[0] is %c\n", mc[0]); printf("Value of mc is %d\n", mc); printf("Value of &mc[0] is %d\n", &mc[0]); printf("Value pointed by mc is %c\n", *mc); } Value of mc[0] is A Value of mc is 107 Value of &mc[0] is 107 Value pointed by mc is A

23 ชื่อแอเรย์เป็นแอดเดรสอยู่แล้ว
หากต้องการกำหนดให้ตัวแปรพอยน์เตอร์ชี้แอเรย์ จึงไม่จำเป็นต้องใช้เครื่องหมาย & เช่น ca = mc; หรืออาจใช้เครื่องหมาย & ก็ได้ แต่ต้องใช้กับสมาชิกตัวหนึ่งเลย เช่น ca = &mc[0];

24 และเมื่อกำหนดให้ ca มีค่าเท่ากับ mc แล้ว ก็สามารถจะใช้ ca แทน mc ได้ กล่าวคือ
*ca คือ ca[0] คือ mc[0] *(ca+1) คือ ca[1] คือ mc[1] *(ca+2) คือ ca[2] คือ mc[2] หรืออาจจะใช้ ca ในรูปของแอเรย์เลยก็ได้ โดยที่ ca[0] คือ mc[0] ca[1] คือ mc[1] ca[2] คือ mc[2]

25 } /* A program to show the use of pointers */ #include <stdio.h>
main() { int i=10; /* i is an integer */ char c='A'; /* c is a character */ float e=5.7; /* e is a float number */ char mc[4]="ABC"; /* mc is an array of char */ char *ca; /* ca is a pointer to char */ int *ia; /* ia is a pointer to int */ printf("Value of mc[0] is %c\n", mc[0]); printf("Value of mc[1] is %c\n", mc[1]); printf("Value of mc[2] is %c\n", mc[2]); ca = mc; printf("Value of ca[0] is %c\n", ca[0]); printf("Value of ca[1] is %c\n", ca[1]); printf("Value of ca[2] is %c\n", ca[2]); printf("Value pointed by *ca is %c\n", *ca); printf("Value pointed by *(ca+1)is %c\n", *(ca+1)); printf("Value pointed by *(ca+2)is %c\n", *(ca+2)); } Value of mc[0] is A Value of mc[1] is B Value of mc[2] is C Value of ca[0] is A Value of ca[1] is B Value of ca[2] is C Value pointed by *ca is A Value pointed by *(ca+1)is B Value pointed by *(ca+2)is C

26 Call-by-Value - ฟังก์ชั่นส่งกลับได้เพียงหนึ่งค่า
/* A program to show the use of pointers */ #include <stdio.h> float average ( int a, int b ) { return ( (a+b)/2.0 ); } main() int n1=1, n2=2; float av; av = average(n1,n2); printf("Average of %d and %d is %0.1f\n", n1, n2, av); Average of 1 and 2 is 1.5

27 /* A program to show the use of pointers */ #include <stdio.h>
float average ( int a, int b ) { printf("Give me two integers : "); scanf("%d %d", &a, &b); return ( (a + b)/2.0 ); } /* Main Function */ main() int n1=1, n2=1; float av; av = average(n1,n2); printf("Average of %d and %d is %0.1f\n", n1, n2, av); ตัวแปร ค่า address (main) 1 1 A100 A101 n2 A102 A103 av 15.5 A104 A105 A106 A107 (average) a 1 5 A108 A109 b 1 26 A110 A111 Give me two integers : 5 26 Average of 1 and 1 is 15.5

28 ฟังก์ชั่นที่ส่งกลับได้หลายค่าด้วยพอยน์เตอร์
/* A program to show the use of pointers */ #include <stdio.h> float average ( int *a, int *b ) { printf("Give me two integers : "); scanf("%d %d", a, b); return ( (*a + *b)/2.0 ); } /* Main Function */ main() int n1=1, n2=1; float av; av = average(&n1,&n2); printf("Average of %d and %d is %0.1f\n", n1, n2, av); ตัวแปร ค่า address n1 1 5 A100 A101 n2 1 26 A102 A103 av 15.5 A104 A105 A106 A107 a A108 A109 A110 A111 b A112 A113 A114 A115 Give me two integers : 5 26 Average of 5 and 26 is 15.5

29 แอเรย์กับฟังก์ชั่นแบบส่งค่ากลับทางพารามิเตอร์
/* A program to show the use of pointers */ #include <stdio.h> int FindMaxScore ( int Score[], int NumberOfStudents) { int MaxScore = -1; int i; for (i=0; i< NumberOfStudents; i++) if (Score[i] > MaxScore) MaxScore = Score[i]; return(MaxScore); } main() int TotalScore[5] = {17, 18, 19, 16, 20}; int NumberOfStudents = 5, MaxTotalScore; MaxTotalScore = FindMaxScore( TotalScore, NumberOfStudents); printf("The maximum total score is %d\n", MaxTotalScore); The maximum total score is 20

30 /* A program to show the use of pointers */ #include <stdio.h>
void GetInput(int Score[], int *N) { int i; printf("How many students: "); scanf("%d", N); /*can also write scanf("%d", &*N) */ for (i=0; i< *N; i++) printf("Enter Score for student %d : ", i+1); scanf("%d", &Score[i]); } int FindMaxScore ( int Score[], int NumberOfStudents) int MaxScore = -1, i; for (i=0; i< NumberOfStudents; i++) if (Score[i] > MaxScore) MaxScore = Score[i]; return(MaxScore); main() int TotalScore[5]; int NumberOfStudents, MaxTotalScore; GetInput(TotalScore, &NumberOfStudents); MaxTotalScore = FindMaxScore( TotalScore, NumberOfStudents); printf("The maximum total score is %d\n", MaxTotalScore); TotalScore[0] 80 A100 A101 TotalScore[1] 90 A102 A103 TotalScore[2] 100 A104 A105 TotalScore[3] 50 A106 A107 TotalScore[4] 60 A108 A109 NumberOfStudents 5 A110 A111 MaxTotalScore A112 A113 How many students: 5 Enter Score for student 1 : 80 Enter Score for student 2 : 90 Enter Score for student 3 : 100 Enter Score for student 4 : 50 Enter Score for student 5 : 60 The maximum total score is 100

31 1. เครื่องหมาย & หน้าตัวแปร หมายถึงแอดเดรสของตัวแปรนั้น
1. เครื่องหมาย & หน้าตัวแปร หมายถึงแอดเดรสของตัวแปรนั้น int *p; int i = 50; p = &i; ตัวแปร ค่า Address p A204 A200 A201 A202 A203 i 50 A205

32 2. เครื่องหมาย * หน้านิพจน์ หมายถึงข้อมูลในแอดเดรสนั้น
x = 3 หมายถึงการเอาค่า 3 มาใส่ลงในหน่วยความจำของตัวแปร x โดยตัวแปร x ต้องเป็นตัวแปรธรรมดา ตัวแปร ค่า Address x 3 A200 A201 int x; x = 3;

33 2. เครื่องหมาย * หน้านิพจน์ หมายถึงข้อมูลในแอดเดรสนั้น
*x = 3 หมายถึงการเอาค่า 3 มา แต่ไม่ได้ใส่ลงในหน่วยความจำของตัวแปร x แต่กระโดดไปยังหน่วยความจำแอดเดรสที่เก็บอยู่ในตัวแปร x และใส่ค่า 3 ลงไป โดยตัวแปร x ต้องเป็นพอยน์เตอร์ ตัวแปร ค่า Address x A204 A200 A201 A202 A203 n 3 A205 int *x, n; x = &n; *x = 3;

34 2. เครื่องหมาย * หน้านิพจน์ หมายถึงข้อมูลในแอดเดรสนั้น
y = x จะหมายถึงการเอาค่าของ x มา ใส่ลงในตำแหน่งของหน่วยความจำของตัวแปร y ตัวแปร ค่า Address x 3 A200 A201 y A202 A203 int x,y; x = 3; y = x;

35 2. เครื่องหมาย * หน้านิพจน์ หมายถึงข้อมูลในแอดเดรสนั้น
y = *x ไม่ได้หมายถึงการเอาค่าของตัวแปร x มา แต่เป็นการเอาแอดเดรสใน x ออกมา แล้วกระโดดไปยังหน่วยความจำตำแหน่งนั้น แล้วเอาค่าออกมา นำไปใส่ให้กับหน่วยความจำของตัวแปร y ตัวแปร ค่า Address x A206 A200 A201 A202 A203 y 3 A204 A205 n A207 int *x,y, n; n = 3; x = &n; y = x;

36 3. การใช้ชื่อของแอเรย์ เช่น Scores หมายถึงแอดเดรสเริ่มตั้นของแอเรย์นั้น
4. การกำหนดพารามิเตอร์ของฟังก์ชั่นเป็นแอเรย์ เช่น int Assignment[] มีความหมายเดียวกับ int *Assignment.

37 5. ในการคำนวณตำแหน่งของพอยน์เตอร์ต้องนับไปเท่ากับ
จำนวนไบต์ที่เก็บข้อมูประเภทนั้น เช่น int *x หมายถึง x เป็นพอยน์เตอร์ของชนิด int ดังนั้น x + 3 จะมีผลลัพธ์เป็นการบวก 6 เข้ากับ x ไม่ใช่บวก 3 เพราะ int มีขนาดเป็น 2 ไบท์ เราจึงต้องบวก 3*2 = 6 เช่นเดียวกัน x[3] ก็หมายถึง *(x + 3) หรือค่าในแอดเดรส x + 6 ตัวแปร ค่า Address *x 5 A200 A201 *(x+1) 3 A202 A203 *(x+2) 7 A204 A205 *(x+3) 1 A206 A207 *(x+4) 9 A208 A209 int x[5] = {5,3,7,1,9};

38 5. ในการคำนวณตำแหน่งของพอยน์เตอร์ต้องนับไปเท่ากับ
จำนวนไบต์ที่เก็บข้อมูประเภทนั้น เช่น float *x หมายถึง x เป็นพอยน์เตอร์ของชนิด float ดังนั้น x + 3 จะมีผลลัพธ์เป็นการบวก 12 เข้ากับ x ไม่ใช่บวก 3 เพราะ float มีขนาดเป็น 4 ไบท์ เราจึงต้องบวก 3*4 = 12 เช่นเดียวกัน x[3] ก็หมายถึง *(x + 3) หรือค่าในแอดเดรส x + 12 ตัวแปร ค่า Address *x 1.5 A200 to A203 *(x+1) 3.9 A204 to A207 *(x+2) 7.2 A208 to A211 *(x+3) 1.82 A212 to A215 *(x+4) 9.25 A216 to A219 float x[5] = {1.5,3.9,7.2,1.82,9.25};

39 6. สำหรับตัวชี้แอเรย์ เช่นถ้ามีการประกาศแอเรย์ int Assignment[10]
การใช้ Assignment[3] มีความหมายเดียวกับ *(Assignment + 3) 7. การใช้เครื่องหมาย &* ติดกัน เช่น &*x จะมีความหมายเช่นเดียวกับการใช้ x โดยลำพัง

40 8. การส่งผ่านตัวแปร ที่ไม่ใช่แอเรย์ เข้าไปเปลี่ยนค่าในฟังก์ชั่น
ในการเรียกฟังก์ชั่นนั้นจะต้องใช้เครื่องหมาย & หน้าตัวแปร และในส่วนของการประกาศพารามิเตอร์ในฟังก์ชั่น และการใช้งานตัวแปรในคำสั่งต่างๆภายในฟังก์ชั่น ต้องใช้เครื่องหมาย * นำหน้าตัวแปรทุกครั้ง เช่น หากตัวแปร mean ประกาศเป็น float mean มีการส่งพอยน์เตอร์นี้เป็นพารามิเตอร์ให้กับฟังก์ชั่น FindAverage โดยเรียกใช้ฟังก์ชั่นเป็น FindAverage(Score, NumberOfStudents, mean void FindAverage(int values[], int N, float *av) { int i, sum=0; for(i=0;i<N;i++) sum += i; *av = sum/N; } void main(void) { int Score[5] = {100,40,98,72, 99}, NumberOfStudents = 5; float mean; FindAverage(Score, NumberOfStudents, &mean);

41 9. การส่งผ่านแอเรย์เป็นพารามิเตอร์ของฟังก์ชั่น ในตอนเรียกฟังก์ชั่นให้ใช้ชื่อแอเรย
เช่น Assignment (โดยไม่มีวงเล็บสี่เหลี่ยมตามหลัง) แต่ในการประกาศพารามิเตอร ให้ใช้การประกาศแอเรย์ตามปกติ int Assignment[] หรือ int *Assignment สำหรับแอเรย์สองมิติขึ้นไป การประกาศพรารามิเตอร์ของฟังก์ชั่น ต้องใส่ตัวเลขในมิติที่ 2 ขึ้นไป (ทุกมิติยกเว้นมิติแรก) เช่น int Matrix[][20] หรือ int *Matrix[20] float ThreeDim[][30][3] หรือ float *ThreeDim[30][3]

42 เช่น หากตัวแปร mean ประกาศเป็น float *mean
10. การส่งผ่านพอยน์เตอร์ไปยังฟังก์ชั่น ในการเรียกฟังก์ชั่นให้ส่งโดยใช้ชื่อพอยน์เตอร์ เช่น หากตัวแปร mean ประกาศเป็น float *mean มีการส่งพอยน์เตอร์นี้เป็นพารามิเตอร์ให้กับฟังก์ชั่น FindAverage โดยเรียกใช้ฟังก์ชั่นเป็น FindAverage(Score, NumberOfStudents, mean) และในการประกาศพารามิเตอร์ในการประกาศฟังก์ชั่น จะต้องเป็นชนิดพอยน์เตอร์ void FindAverage(int values[], int N, float *av) { int i, sum=0; for(i=0;i<N;i++) sum += i; *av = sum/N; } void main(void) { int Score[5] = {100,40,98,72, 99}, NumberOfStudents = 5; float *mean; FindAverage(Score, NumberOfStudents, mean);


ดาวน์โหลด ppt หน่วยที่ แอเรย์และพอยน์เตอร์

งานนำเสนอที่คล้ายกัน


Ads by Google