Dynamic arrays in C without malloc?

前端 未结 4 498
不知归路
不知归路 2020-12-10 10:58

I\'ve always wondered how I could get away with this:

int main(int argc, char **argv) {
    printf(\"%p %s %d\\n\", &argv[1], argv[1], strlen(argv[1]));
         


        
4条回答
  •  失恋的感觉
    2020-12-10 11:45

    Variable-length arrays originated as a GCC extension, but they were also adopted by C99.

    They are still being allocated on the stack, so making them "huge" is considered bad style (and will likely break on you someday).

提交回复
热议问题