How many characters can string variable hold?

closed account (3hMz8vqX)
Hi all,
How many characters can string variable hold?
ex :
string a="apple";
like what is the max num of chars a can hold?
Long answer:

There's a hard limit based on the size of size_t. Most implementations have size_t as 32 bits, so that means the max is 232 - 1 or 4294967295 characters.

Though in practice you're more likely to be limited by the amount of continuous space that can be allocated. Which depends on how much memory your system has and how fragmented it is.




Short answer:

Don't worry about it. The limit is extremely high. You aren't likely to exceed it.
Last edited on
No offence Avarind but you should realize that simply typing the title of your posts into Google will give you an immediate answer to your questions. If you had just Googled "How many characters can string variable hold?" you would have found out that C++ strings have a method to provide you with the max size: std::string::max_size()

Why wait around to be spoon-fed (possibly wrong!) answers when you can get what you need and more right now by learning to do some research? Just sayin...
Topic archived. No new replies allowed.