How many chars can be in a char array?

后端 未结 6 765
广开言路
广开言路 2020-12-01 12:40
#define HUGE_NUMBER ???

char string[HUGE_NUMBER];
do_something_with_the_string(string);

I was wondering what would be the maximum number that I co

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 12:57

    If the array is going to be allocated on the stack, then you are limited by the stack size (typically 1MB on Windows, some of it will be used so you have even less). Otherwise I imagine the limit would be quite large.

    However, making the array really big is not a solution to buffer overflow issues. Don't do it. Use functions that have a mechanism for limiting the amount of buffer they use to make sure you don't overstep your buffer, and make the size something more reasonable (1K for example).

提交回复
热议问题