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
What is the purpose of ios::basefield in the following statement?
What can c++ be used for?
What is the role of static keyword for a class member variable?
Write a program for Divide a number with 2 and Print the output ( NOTE: Check for divide by zero error).
Can member functions be private?
What are the uses of pointers?
Can a new be used in place of old mallocq? If yes, why?
How do I write a c++ program?
What are the benefits of c++?
What is the best c++ book?
In what situations do you have to use initialization list rather than assignment in constructors?
How do you print a string on the printer?
Are c and c++ similar?
What does it mean to declare a destructor as static?
Why was c++ created?