Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

40
  • 35
    char *temp = "foo bar"; is a valid statement in C... hey! isn't that a string? isn't it null terminated? Commented Dec 11, 2010 at 20:22
  • 62
    @Yanick: that's just a convenient way to tell the compiler to create an array of char with a null at the end. it's not a 'string' Commented Dec 11, 2010 at 20:24
  • 34
    @calavera: But it could have just as simply meant "Create a memory buffer with this string content and a two byte length prefix", Commented Dec 11, 2010 at 20:28
  • 16
    @Billy: well since a 'string' is really just a pointer to char, which is equivalent to a pointer to byte, how would you know that the buffer you're dealing with is really intended to be a 'string'? you would need a new type other than char/byte* to denote this. maybe a struct? Commented Dec 11, 2010 at 20:33
  • 28
    I think @calavera is right, C doesn't have a data type for strings. Ok, you can consider an array of chars like a string, but this doesn't mean it's always a string (for string I mean a sequence of characters with a definite meaning). A binary file is an array of chars, but those chars don't mean anything for a human. Commented Dec 11, 2010 at 20:48