Is there a datatype string in c++?How is the memory allocation?

Answer Posted / ganesh chincholkar

Yes true string is not a datatype in C++ but it is implemented through Standard Template Library. And the string class has dynamic memory allocation.
eg:-
string str;
cin>>str;

string str gets dynamically allocated storage and that storage size is not permanent and can be modifies later.

after:
what happens behind screen is actualy:
string str = new char[strlen(str) + 1];
when you take input of the string str its size is calculated and you get the desired meomry.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Difference between overloading vs. Overriding

816


What is lambda in c++?

886


Why is c++ still popular?

786


What is size_type?

719


What is c++ code?

818


What are put and get pointers?

832


If dog is a friend of boy, and terrier derives from dog, is terrier a friend of boy?

812


What are the advantages of prototyping?

791


What is java and c++?

880


Is there any function that can skip certain number of characters present in the input stream?

793


What does ctime() do?

797


What c++ library is string in?

786


Define friend function.

780


Explain the extern storage classes in c++.

769


How do you declare A pointer to a function which receives nothing and returns nothing

946