Re: C Strings
- From: "subramanian100in@xxxxxxxxx, India" <subramanian100in@xxxxxxxxx>
- Date: 3 Mar 2007 20:44:19 -0800
On Mar 4, 7:01 am, Beej Jorgensen <b...@xxxxxxx> wrote:
Mark McIntyre <markmcint...@xxxxxxxxxxx> wrote:
I was thinking of string literals, which aren't arrays, but point
taken and pun intended.
I thought string literals were arrays until you operated on them, at
which point they became char*s?
#include <stdio.h>
int main(void)
{
char *p1;
char (*p2)[];
p1 = "foobar";
p2 = &"foobar";
p1 = &"foobar"; /* invalid */
p2 = "foobar"; /* invalid */
printf("%zu\n", sizeof("foobar")); /* "7" */
printf("%zu\n", sizeof("foobar"+0)); /* "4" */
return 0;
}
-Beej
Here consider the two lines:
printf("%zu\n", sizeof("foobar")); /* "7" */
printf("%zu\n", sizeof("foobar"+0)); /* "4" */
What is %z?
What is the effect of adding 0 to "foobar" ?
The reason for asking these questions is that VC++2005 does not
recognize %z (In K&R 2nd edition also, I could not find %z). Also,
when I have %u instead of %zu, VC++ 2005 prints 7 and 7 for both
printf statements.
.
- Follow-Ups:
- Re: C Strings
- From: santosh
- Re: C Strings
- References:
- C Strings
- From: cman
- Re: C Strings
- From: Mark McIntyre
- Re: C Strings
- From: Keith Thompson
- Re: C Strings
- From: Mark McIntyre
- Re: C Strings
- From: Beej Jorgensen
- C Strings
- Prev by Date: Re: porting vs migrating
- Next by Date: end of array
- Previous by thread: Re: C Strings
- Next by thread: Re: C Strings
- Index(es):
Relevant Pages
|