A little question
#1

Hello guys. I have a little question. Let's say we have this string:
Код:
new string[128];
Its length will be 128 characters. Now, let's say we have this string:
Код:
new string;
Will it have a dynamic length? I mean, at first, it will be limited at 1 character (the null). If you store "black" in it, will it be a 6 character limited string? So it will change its length automatically?

The main question is, why do we have to limit the strings, instead of using this (the code below)? If we are using this code, the string will automatically be limited at 1024 characters? (so it will use more memory for nothing, and that's the reason why we should limit the string's length?)
Код:
new string;
Reply
#2

Код:
    new str;
	printf("%d",sizeof(str));
	str = 4465498;
	printf("%d",sizeof(str));
Result :
Код:
[19:13:07] 1
[19:13:07] 1
It will have size 1 and you can not store "Black" in it.
So, the string wont be using 1024 of memory, but just 1 byte.
Hence, you must limit the strings.
Reply
#3

Thank you very much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)