Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   How scanf identify our inputs? (http://www.go4expert.com/forums/scanf-identify-inputs-t3200/)

sebasr 28Feb2007 20:02

How scanf identify our inputs?
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 1Mar2007 11:27

Re: How scanf identify our inputs?
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 1Mar2007 16:09

Re: How scanf identify our inputs?
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.

All times are GMT +5.5. The time now is 12:50.