[問題] 遞增and遞減
這是在課本的作業題看到的,
題目是說:請問程式的輸出結果為何?
#include <stdio.h>
#define FORMAT "%s is a string\n"
int main(void)
{
int num = 0;
printf(FORMAT,FORMAT);
printf("%d\n", ++num);
printf("%d\n", num++);
printf("%d\n", --num);
printf("%d\n", num--);
printf("%d\n", num);
retrun 0;
}
=============================
以下是我沒用compiler自己寫的:
%s is a string
%s is a string
1
1
-1
-1
0
=============================
經過電腦compiler的答案:
%s is a string
is a string
1
1
1
1
0
為什麼會差那麼多,麻煩幫我講解一下我的問題出在哪??
謝謝大家的幫忙!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 58.115.134.161
→
08/17 22:32, , 1F
08/17 22:32, 1F
→
08/17 22:32, , 2F
08/17 22:32, 2F
→
08/17 22:33, , 3F
08/17 22:33, 3F
→
08/17 22:34, , 4F
08/17 22:34, 4F
→
08/17 22:37, , 5F
08/17 22:37, 5F
→
08/17 22:42, , 6F
08/17 22:42, 6F
很謝謝你們的提示,原來是我搞混了,非常謝謝你們的幫忙,感激不盡!!
※ 編輯: shile775 來自: 58.115.134.161 (08/17 22:56)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章