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

Lâm Phung

New member
What will be the output of the following C++ code?
Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
        string str ("Steve jobs");
        cout << str.capacity() << "\n";
        return 0;
    }
A. 9
B. 10
C. 11
D. Not Fix
 
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. So the answer is not fix, depends on the compiler.
Output:
Code:
$ g++ basicst1.cpp
$ a.out
10
 

Tìm kiếm

Back
Top