How scanf identify our inputs?

sebasr's Avatar
Newbie Member
I came a question in a C exam. The Q is,

How does the scanf identify the 255 entered from terminal
a) 0xff
c)or like hex for 2 then5 then5

These are the options given.
Anyone knows some explanation pls share

shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
It depends on what you are storing the value 255. If its 8 bit (1 byte) it will be a option if its more bytes then b can also be a probable but I would still go with a.
DaWei's Avatar, Join Date: Dec 2006
Team Leader
If you press the keys, '2', '5', and '5' on the keyboard, scanf will deal with them according to your format specifier(s). Using that, it will store them (or fail), as a binary value, in the specified variables of the specified type. Your question, as phrased, is almost meaningless. All values are binary, in the computer. There is no hex or decimal or anything else. Those are representations for YOUR brain. The binary may be interpreted in differing ways, e.g., float, integer, gating pattern or mask. That's why we have typing (explicit or implicit).

Incidentally, virtually no keyboard in common use would produce the binary value, 2, for key '2', or 5 for key '5'. There are layers of interpretation in play.

Last edited by DaWei; 1Mar2007 at 16:12..