scanf
wants a correct address where to store the result:
(A) int i=0; scanf("%d", i);
i
is passed here by value, no address: wrong.
(B) int i=0; int *p=&i; scanf("%d", p);
p
is a pointer to int, scanf
can store its result here: right
(C) char *s="1234567"; scanf("%3s", &s);
&s
is the address of a pointer to char *
, you cannot store a string there: wrong
(D) char c; scanf("%c", c);
c
is passed by value, not an address: wrong
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…