+ 3

What Size Does A String Variable Occupy ?

If I declare a string name and do not assign anything to it , the sizeof operator returns size of 32 bytes , but what if I store a string greater than 32 characters in it ? Would it write the extra characters in some unreserved memory ? https://code.sololearn.com/c35qYPDSXOfz/?ref=app

7th Jul 2018, 5:13 AM
Aayush Bhansali
Aayush Bhansali - avatar
2 odpowiedzi
+ 1
string has internally array of chars which is resized every time you add element which goes beyond reserved memory. So string memory depends on number of elements it stores.
7th Jul 2018, 11:19 AM
Jakub Stasiak
Jakub Stasiak - avatar
7th Jul 2018, 6:50 AM
hinanawi
hinanawi - avatar