-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
@ Robert
so u mean to say that this statement will behave differently on the
different compilers??
i also tried out
printf("%d",'+a'); and it gives 11105 on g++ (linux) and turboC
(windows) i dont think they are compiler dependednt...
Certainly, the results will be compiler dependant. It's just that both
of your compilers give the same results
Consider that the result depends on
- - the width (sizeof()) of a character constant (hint: it isn't
necessarily == 1)
- - the 'endianness' of a character constant (hint: it isn't necessarily
little-endian)
- - the characterset used to express characters in (hint: it isn't always
ASCII)
Think of what the differences might be between your results and the
results of the same program when compiled and run on a system with
- - 32bit integer values
- - big-endian integers
- - EBCDIC-US characterset
Can someone please tell me as to why the compiler behaves in the
following way?? (43*256+43=11051)
Because, on /your/ system, character constants are stored as 16bit
integer values, in the ASCII characterset. Since the ASCII for '+' is
binary 43, then the first '+' (being shifted left into the high-order 8
bits of your 16bit integer) becomes 43*256 (or 43 << 8). The second '+'
(not moving from the low-order position) becomes 43. And the combination
of the two (a 16bit integer, remember?) becomes (45*256)+43
- --
Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
iD8DBQFDq/8+agVFX4UWr64RAnAEAJ95BsHcGCYBqkvNRyHHzggeNFTPZwCeJvP6
ymeBG+DMNGdtX6rSOY+HKVI=
=Ra/t
-----END PGP SIGNATURE-----