习题8_6与习题9_2
生活随笔
收集整理的這篇文章主要介紹了
习题8_6与习题9_2
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
習題8_6
這個是我最開始的錯誤代碼:
void delchar( char *str, char c )
{char* p;p=str;char* tool;while(p!='\0') {if(c==*p){tool=p;while(tool!='\0'){*tool=*(tool+1);tool++;}}elsep++;}
}
原因在于:我的需要比較指針的值的話需要*,在運用指針的時候一定要注意。
以下是正確代碼:
void delchar( char *str, char c )
{char* p;p=str;char* tool;while(*p!='\0') {if(c==*p){tool=p;while(*tool!='\0'){*tool=*(tool+1);tool++;}}elsep++;}
}
下面是習題9_2:
我開始完成的代碼是:
struct complex multiply(struct complex x, struct complex y)
{struct complex put;put->real=x->real*y->real-x->imag*y.imag;put->imag=x->real*y->imag+x->imag*y.real;return put;
}
發現代碼無法編譯,但在我將 . 改為->之后卻可以了,即:
struct complex multiply(struct complex x, struct complex y)
{struct complex put;put.real=x.real*y.real-x.imag*y.imag;put.imag=x.real*y.imag+x.imag*y.real;return put;
}
在查閱資料后發現,. 用于結構體變量,而**->**用于結構體指針。
總結
以上是生活随笔為你收集整理的习题8_6与习题9_2的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 治疗弱精最多要多少钱
- 下一篇: 加盟鸭脖多少钱啊?