Page 33 - PIC18F4550微處理機C語言設計實務
P. 33
ሔଡ଼ΥႧԊձ C ႧԊ 1
ܸᅺהܸٙЗѧʘʫ࢙הᎷπٙ༟ࣘۨ࿒ * ܸᅺΤ၈ ;
Էνj
int *ipointer; // ੭ୌᅰ࠽π׳Зѧܸٙᅺ ipointer
char *cpointer; // 8 Зʩ༟ࣘʫ࢙π׳Зѧܸٙᅺ cpointer
܁ѓۨ࿒ʑঐٝ༸ܸᅺӊ̋ 1 ࣛdࠅ༪ཀεˇЗʩଡ଼f
ίਂ܁ѓމܸᅺࣛdܸᅺΤ၈ۃࠦࠅ̋ * fࠅܸᅺπ՟הܸٙЗѧʘʫ࢙ࣛd
ίܸᅺۃࠦࠅ̋ * f
Էνj
unsigned char Array[] = {0,1,2,3};
unsigned char *cpointer;
cpointer = &Array[0]; // ਗ਼ cpointer ܸᅺܸΣ Array[0] ٙЗѧ
*cpointer = 1; // ਗ਼ cpointer ܸᅺܸΣٙЗѧɰఱ݊ Array[0]
ࡌҷމ 1dੂБഐҼʘܝ Array[] ৬ΐٙʫ࢙ਗ਼ᜊϓ {1,1,2,3}
ࠅ༶ၑאܸݼassign˸՟ܸᅺהܸٙЗѧࣛdܸᅺΤ၈ۃࠦʔ̋ * f
Էνj
ટᚃɪࠦٙ܁ѓd߰ࠅࡌҷ Array[1] ٙʫ࢙d˙جνɨj
cpointer = cpointer+1;
*cpointer = 5;
Ϊމ cpointer ݊܁ѓމ unsigned char ܸٙᅺdה˸ +1 ڌͪЗѧᄣ̋ɓࡈ Byted
ΪϤ +1 ʘܝܸ݊Ց Array[1] ٙЗѧf
ੂБഐҼʘܝ Array[] ৬ΐٙʫ࢙ਗ਼ᜊϓ {1,5,2,3}f
Ңࡁ̙˸Դ͜ & ༶ၑɿ՟̈ᜊᅰٙЗѧ࠽Ԩܸ֛ഗܸᅺdԷνj
int abc = 0x3d ; // ܁ѓɓࡈᅰᜊᅰ abcdՉʫ࢙݊ 0x3d
int *iptr = &abc ; // ܁ѓɓࡈܸᅺ *iptr ܸΣᅰᜊᅰ abc ٙЗѧ
iptr = iptr+1; // ܸᅺ *iptr ܸΣɨɓࡈЗѧiptr ʫ࢙̋ 2dΪމ݊ᅰ
*iptr = *iptr + 1; // ܸᅺ *iptr הܸٙাኳʫ࢙̋ 1diptr ʫ࢙Ӛᜊ
ܸᅺٙࠠᓃ̌ঐ̙݊˸༶ၑ˸՟הࠅٙЗѧdৰəܸ֛༶ၑ =d՟ѧ༶ၑɿ
& ၾ՟࠽༶ၑɿ * ̮dᒔϞ̋ +eಯ –eᄣ ++eಯ ––e̋ܝܸ֛ += ၾಯܝ
ܸ֛ –= ഃ༶ၑɿ̙˸Դ͜f
23