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*

18
  • 7
    While true, this is hardly the biggest difference. What's the difference between &amessage and &pmessage, for example? Commented Aug 26, 2009 at 16:12
  • 2
    &pmessage will be the address of pmessage, somewhere on the stack. Likewise, &amessage will be the address of the array on the stack, same as amessage. However, &amessage has a different type than amessage. Commented Aug 26, 2009 at 16:24
  • 5
    No, it's not undefined. The difference is that the type of &pmessage is char** - pointer to pointer to char, and the type of &amessage is char(*)[16] - pointer to array of 16 chars. Those two types are not compatible (the second one, in particular, is simply address of the first character in the string, while the first one is address of variable that stores the address of the first character). Commented Aug 26, 2009 at 16:24
  • Weird, I guess C does do that. I figured &amessage would be invalid as amessage is resolved to a code-constant pointer . . . Commented Aug 26, 2009 at 16:27
  • 1
    @Bill: Nah, cause the array version is actually just a shortcut for array instantiation. So the array is allocated in the stack, and then loaded with the string's data. Commented Aug 26, 2009 at 17:42