Page 31 - PIC18F4550微處理機C語言設計實務
P. 31
ሔଡ଼ΥႧԊձ C ႧԊ 1
༟ࣘۨ࿒̙˸݊ intechar ഃd˸ɨ݊ࡈ৬ΐ܁ѓٙᇍԷj
int age[30]; // ܁ѓ 30 ࡈπ׳ϋߏٙᅰ৬ΐf
char ave[30]; // ܁ѓ 30 ࡈπ׳̻ѩϓᐶٙɓࡈЗʩଡ଼৬ΐf
܁ѓ৬ΐ̙ࣛ˸ഗ࠽אৰd˸е՟ʔᆽ֛ٙ࠽fഗ࠽ࠅ͜ഃܝ͜ɽܼਗ਼
࠽ՒৎԸd࠽ၾ࠽ගԴ͜ஸʱකf
Էνj
int score[5] = {0,0,0,0,0}; // ৬ΐʕٙʩ९ேึڋމ 0f
char symbol[] = {'a', 'b', 'c', 'd', 'e', '\0'}; // ఊɓοʩۃܝԴ
͜ఊˏf
ۆ symbol[0]= 'a'dsymbol[1]= 'b'd....dsymbol[4]= 'e'f
ձ˸ɨٙοʩ৬ΐ܁ѓΝj
char symbol[] = "abcde"; οЕۃܝ͜ᕐˏfοЕఱ݊οʩٙ৬ΐf
̥݊οЕึІਗ̋ɝഐҼοʩ '\0'f
ࠅπ՟৬ΐʕٙʫ࢙ࣛdԴ͜৬ΐΤ၈̋ɪ [ ]dί [ ] ʕ̋ɪ॰ˏ࠽Indexd
॰ˏ࠽̙˸݊ɓࡈᜊᅰא݊ɓࡈ༶ၑόdܸ֛ࠅπ՟৬ΐʕٙ࿁ʩ९f॰ˏ࠽ɓܛ
͟ 0 කdϾʔ݊͟ 1 කf॰ˏ࠽ఱ݊৬ΐʕʩ९ٙᇜf
■ 二維陣列
ɚၪ৬ΐ݊Դ͜৬ΐΤ၈ၾՇࡈ॰ˏ࠽Ըܸ֛π՟৬ΐʩ९dՉ܁ѓ˙ό݊৬ΐ
ۨ࿒e৬ΐΤ၈ձՇࡈ৬ΐୌ [ ]f
Էνj
int score [30][3];
݊܁ѓɓࡈ 30*3=90 ࡈπ׳ᅰٙাኳ٤ගΤ̣ score ৬ΐfɚၪ৬ΐԴ͜Շࡈ
॰ˏ࠽Ըܸ֛π՟৬ΐdவՇࡈ॰ˏ࠽ே݊͟ 0 කf
ɰ̙˸ί܁ѓɚၪ৬ΐٙΝܸ֛ࣛɚၪ৬ΐٙ࠽f
Էνj
int score [3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
܁ѓɓࡈΤ̣ score 3 ΐ 4 Бٙ৬ΐdԴ͜ { } ၾቇٙஸᓃԸ່֛৬ΐٙڋ࠽d
Չʕdʫٙɽܼ̙݊˸ଫf
21