Search:

Type: Posts; User: c99tutorial

Search: Search took 0.01 seconds.

  1. You already did. char buf[100]; If...

    You already did.



    char buf[100];


    If you reference *buf within this scope, the compiler knows that *buf is a char, and it also knows that sizeof buf is 100.
  2. In C, aggregates are treated as pointers. So buf...

    In C, aggregates are treated as pointers. So buf is a pointer to char, *buf is a char, and sizeof(char) is 1, of course. If buf is an array of something else, then the size will change accordingly.
    ...
  3. Suppose you write this char buf[1000];...

    Suppose you write this



    char buf[1000];
    printf("%d\n", NELEMS(buf));


    sizeof buf is 1000 and sizeof *buf is 1, so the result is 1000 elements. The nice thing about the macro is that it...
  4. I usually use this macro: #define...

    I usually use this macro:


    #define NELEMS(obj) (sizeof(obj)/sizeof(*obj))


    Then you can just write NELEMS(array)
Results 1 to 4 of 4