manish sahu said:
in memory characters are stored in form of ascii values
This is not necessarily true. _Most_ implementations store characters as
ASCII values, but other encodings are allowed (EBCDIC, for example; or
Unicode).
my question is that
Is it also true for integer value if yes how??
also true for real (float and double) values??
Why on earth would you store a floating point value as ASCII values?
No, integer types are stored as a binary number, and floating point
values are stored as, surprise, a floating point number. How exactly
these are stored in memory depends on the implementation, but the
Standard guarantees this:
For integer types,
- exactly one sign bit, if and only if it's a signed type;
- a number of value bits, each of which represents one position in the
corresponding binary representation;
- possibly a number of padding bits, which do not contribute to the
value of the number. (Most implementations have no padding bits, but
they're allowed to. And padding bits may contribute to trap
representations.)
Nothing is said of how these bits are arranged within the bytes that
make up an integer value, but obviously little- and big-endian are the
most common.
For floating point types, nothing at all is defined about the layout of
the value in memory, but the following is said of what makes up that
value:
- there is a sign;
- there is a base, which must be integer (_not_ a C integer value, but
a conceptual integer underlying the type) and >1, _and_ this base is
the same for all floating types within this implementation;
- there is an exponent, which is also integer and must lie between a
given minimum and maximum value which may differ between types;
- there is a precision, which is the number of base-b digits in the
significand, and which may vary between types;
- there are the significand digits;
- all the above make up the floating point value in a way which is too
complicated to get across reliably in a Usenet post, but which can
be found in any reasonable textbook which covers FP math.
As you can see, the base, the size of the exponent, and the precision,
i.e. the size of the significand part, are fixed within the type, and
therefore need not be represented within each floating point number's
value. Surprisingly enough, though, they're allowed to be (though I know
of no implementation which does so).
As you can also see, the values of the sign, exponent, and significand
digits _do_ vary between individual FP values, and must therefore be
encoded within the FP representation. But, I repeat, the Standard
demands _nothing_ about how they are encoded. As with integers, most
implementations will use one of a limited common formats (usually some
form of IEC 60559, I think), and even those that don't will generally
use base 2 or 16, not 3 or 37.
One other thing: for all of the above, the Standard guarantees minimum
values, but not maxima. For example, a short int must be able to hold at
least the values -32767 to 32767, and the exponent of any floating point
number must be able to run to at least 37. But any implementation is
allowed to admit greater values.
Most importantly, though: if you have to ask this question, you should
not need to know the answer. Let the implementation take care of how it
arranges your longs doubles in memory; you should care only of their
values, and their sizes in bytes - and the latter only for memory
allocation and copying.
Richard