hi all,
Characters are basically implemented via integers,ex : '\0' is 0.But
integers requires 2 bytes and the characters require only 1
byte.So,can anybody please tell me that how the charcters are
implemented via integers.
Whoever told you that integers are 2 bytes lied. And whoever told you
that characters are only 1 byte large did too.
The type char although its name probably implies something else is a
integer type. In C a char is by definition 1 byte large. This must not
be confused with characters in the sense of written letters or symbols.
Also note that 1 byte in C need not necessarily be 8 bits, but in many
implementations actually is.
A character on the other hand is something the implementation (your
computer in conjunction with the used compiler and environment) is to
interpret on one way or the other. How characters are interpreted is not
actually defined bye the C-standard. There are only some constraints
given to the implementation, so that a basic set of characters is made
available by all implementations claiming conformance.
One of the constraints given by the standard is that the representation
of a character from that basic set must fit into a byte, which is it
must fit in to a variable of type "char". But as you probably can
imagine a implementation might give you some optional characters that
would extend the basic set. The represetations of such characters need
not fit into a byte/char. But if the implementation should be able to
allow for literals in your programs for example it should also be able
to store characters into integer variables that are not of type char but
bigger. Therefor literal characters are of type int which is a integer
type that is as big or bigger than short, which depending on the
implementation might mean that it is 1 byte (if a byte would consist of
at least 16 value bits) large but might also be 2, 3, 4, or any other.
You might have recopgnized that a value that can be stored in 1 byte
can always be stored in two bytes or more.
I hope this doesn't confuse you even more, but if it does, don't
hasitate to ask for more clearification, I'm sure some regulars in CLC
will point you in the right direction.