fidlee said:
Keith Thompson wrote:
.... snip ...
sorry. my mistake.
it was actually
1)
char a='i';
printf("%d",sizeof(a));
2)
char a='i';
printf("%d",sizeof('i'));
this problem comes up in turbo C
Congratulations on learning to quote, and to avoid silly
abbreviations. To avoid mistakes you should also always cut and
paste your code samples (from compilable source). This avoids
silly typos invalidating any conclusions.
In this newsgroup we deal only with ISO standard C. Thus the fact
that you are using Turbo C does not matter. What does matter is
that you are using only features of standard C, and no extensions
such as Turbos <conio.h> That way we are all talking about the
same language.
The differences you are seeing in your code are because 'i' is an
integer constant, and thus its size is that of an int. However it
can be stored in a char (the int is sufficiently small), and the
sizeof a char is 1 by definition.
These relative sizes, for your system, are spelled out in the
include file <limits.h> Thus your code can always adapt to the
actual situation.
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <
http://cfaj.freeshell.org/google/>