SungJin Park
SungJin Park

Reputation: 51

Difference between %d%d and %d %d

Does scanf("%d%d"); act like scanf("%d %d");?

or

Does scanf("%d %d"); act like scanf("%d%d);?

or

They are not the same?

I know that white space consumes any input white space in the buffer.

When I input [32 44] how they distinguish 32 is first %d and 44 is second %d, if it is true?

Upvotes: 0

Views: 574

Answers (1)

Steve Summit
Steve Summit

Reputation: 48043

Yes, "%d%d" and "%d %d" will perform identically with scanf.

In a scanf format specifier, %d means "skip any whitespace, then read an integer".

In a scanf format specifier, a space character means "skip any whitespace".

So "%d%d" means "skip any whitespace, then read an integer, then skip any whitespace, then read an integer".

And "%d %d" means "skip any whitespace, then read an integer, then skip any whitespace, then skip any whitespace, then read an integer".

Upvotes: 5

Related Questions