4 ms·
Of course sizeof already has that capability since C has variable length arrays. They are kind of being phased out, but they are there. You can do this: #
by unwind 2y ago
Of course sizeof already has that capability since C has variable length arrays. They are kind of being phased out, but they are there.
You can do this:
#include <stdio.h>
int main(int argc, char *argv[]) {
unsigned int lens[argc];
for (int i = 0; i < argc; ++i)
lens[i] = (int) strlen(argv[i]);
printf("Computed %d lens into %zu bytes of array\n", argc, sizeof lens);
return 0;
}
Very contrived pointless example, but still.