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*

9
  • Sounds like you have perhaps answered your own question. Commented Sep 30, 2014 at 1:15
  • argv[1] has type char *, so sizeof argv[1] means sizeof(char *). That's what sizeof does. Commented Sep 30, 2014 at 1:18
  • But why does buf10 print 10 and argv[1] not print 9. buf10 is also a pointer is it not? Commented Sep 30, 2014 at 1:20
  • 2
    buf10 is an array type, not a pointer. Commented Sep 30, 2014 at 1:38
  • 1
    @StevenK Both are available at compile-time; the question is whether the compiler will apply the optimisation in that case. You should use %zu to print size_t values... Okay, I misunderstood your question initially. Perhaps a more illuminating example: char *fubar = "hello world"; What kind of value do you expect sizeof NULL to produce, compared to sizeof fubar? Should sizeof attempt to follow the pointer to find out the size of that which is pointed at? If so, then the first example is surely invalid, right? Commented Jan 16, 2016 at 17:31