Re: sizeof()'s strange behviour
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Tue, 08 Apr 2008 09:06:48 -0700
Richard Heathfield <rjh@xxxxxxxxxxxxxxx> writes:
arnuld said:[...]
[...]printf("sizeof(%s): %d\n", s, sizeof(s));
...so we'd expect this to print 16 in place of the second % format
specifier. Note that your printf is misleading. It will print:
sizeof(Saurabh Nirkhey): 16
but in fact it's sizeof s that is 16.
Furthermore, "%d" causes printf to expect an int argument, but
sizeof(s) is of type size_t. It's likely to happen to work on systems
where int and size_t are the same size, but the right way is (with a
couple of other tweaks):
printf("sizeof s: %d\n", (int)sizeof s);
--
Keith Thompson (The_Other_Keith) <kst-u@xxxxxxx>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: sizeof()'s strange behviour
- From: Philip Potter
- Re: sizeof()'s strange behviour
- References:
- sizeof()'s strange behviour
- From: arnuld
- Re: sizeof()'s strange behviour
- From: Richard Heathfield
- sizeof()'s strange behviour
- Prev by Date: Re: How to make it faster?
- Next by Date: Re: problem with multiple source file
- Previous by thread: Re: sizeof()'s strange behviour
- Next by thread: Re: sizeof()'s strange behviour
- Index(es):
Relevant Pages
|