我正在學習隊列,我碰到這段代碼。它來自一本書,所以我不能在這裏發佈整個代碼,但是我發佈的內容就足夠了。不僅僅是一個問題,我只想確認我對這段代碼的理解是否正確。如果 - 其他問題
在函數delete_ap()中,'if'語句調用qretrieve()函數並將其返回值存儲在指針'p'中。 我的問題是:如果返回的值不是NULL,那麼'if'語句也會被執行,不是嗎? 所以一個值仍然存儲在'p'中,我們可以在不使用本示例中使用的'else'語句的情況下打印此值。
謝謝!
/* Delete an appointment from the queue. */
void delete_ap(void)
{
char *p;
if((p=qretrieve()) ==NULL) return;
printf("%s\n", p); <--Problem is in this line and the one above it.
}
/* Retrieve an appointment. */
char *qretrieve(void)
{
if(rpos==spos) /* spos:holds the index of the next free storage location.
rpos:holds the index of the next item to retrieve.*/
{
printf("No more appointments.\n");
return NULL;
}
rpos++;
return p[rpos-1];
}
你能在這裏包的代碼位代碼塊?編輯你的文章,選擇所有的代碼,然後點擊看起來像兩行0和1的按鈕。這是不可能的,否則... – Stephen 2010-08-21 10:10:43
對不起,我忘了包裝它。 感謝您編輯KennyTM。 – Naruto 2010-08-21 10:14:52
誰寫這本書寫*醜*代碼。 – James 2010-08-21 10:18:33