Skip to content

I have come across this code snippet as shown below. Can anyone suggest what is the meaning of a in scanf function

An answer to this question on Stack Overflow.

Question

Can anyone suggest what is the meaning of a in the following call to scanf?

scanf("%d a %f",&i,&f)

Answer

Characters preceded by a '%' in a call to scanf represent variables.

For instance %d represents an integer variable whereas %f represents a floating-point variable.

Characters which are not preceded by a % (or a \, which indicates an escape sequence) are taken literally, so, in your case, the scanf string "%d a %f" would match "233 a 4.5" but would not match "233 b 4.5".

(To be more accurate, a whitespace character matches any contiguous sequence of whitespace characters.)