What will be the output of the following C++ code? [code] #include <iostream> #include <string> using namespace std; int

What will be the output of the following C++ code?
Code:
   #include <iostream>
   #include <string>
   using namespace std;
   int main ()
   {
       string str ("Ubuntu");
       cout << str.capacity();
       cout << str.max_size();
       return 0;
   }
A. 61073741820
B. 51073741820
C. 6 and max size depends on compiler
D.
15
9223372036854775807
 
Answer: d
Explanation: str.capacity() returns the size of the storage space currently allocated for the string, expressed in terms of bytes and capacity of the string may be equal or greater. The max_size() returns the max size of the string.
Output:
Code:
$ g++ stri5.cpp
$ a.out
15
9223372036854775807
 

Tìm kiếm

Back
Top