Loading...

C++ Multiple Choice Questions

Our C++ questions and answers focuses on all areas of C++ programming language covering 100+ topics in C++

C++ Arrays & Strings MCQ | Set 2

C++ Arrays & Strings | Set 2


11. Which header file is used to manipulate the string?

a) iostream
b) iomanip
c) string
d) container



12. How many maximum number of parameters does a string constructor can take?

a) 1
b) 2
c) 3
d) 4



13. Which constant member functions does not modify the string?

a) bool empty()
b) assign
c) append
d) delete



14. What is the difference between unsigned int length() and unsigned int size()?

a) Returns a different value
b) They are same
c) Returns a different value but they are same
d) Returns a length



15. What will be the output of the following C++ 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



16. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main() {
    string str {"Steve jobs founded the apple"};
    string str {"apple"};
    unsigned found = str.find(str2);
    if (found != string :: npos)
    cout << found << "\n";

    return 0;
}

a) apple
b) 12
c) 23
d) Steve jobs founded the



17. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main() {
    string str {"Steve jobs"};
    unsigned long int found = str.find_first_of("aeiou");
    while (found != string :: npos)
    {
        str[found] = '*';
        found = str.find_first_of("aeiou", found + 1);
    }
    cout << str << "\n";

    return 0;
}

a) Steve
b) jobs
c) St*v* j*bs
d) St*v*



18. What will be the output of the following C++ code?
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main() {
    string str {"Steve jobs"};
    char * cstr = new char [str.length() + 1];
    strcpy (cstr, str.c_str());
    char * p = strtok (cstr, " ");
    while (p != 0)
    {
        cout << p << "\n";
        p = strtok(NULL, " ");
    }
    delete[] cstr;

    return 0;
}

a) Steve jo
b) Steve jobs
c) Steve
jobs
d) Steve jo



19. How many parameters can a resize method take?

a) 1
b) 2
c) 1 or 2
d) 2



20. Which of the following is correct about remove_extent() function?

a) Removes the given dimension from an array
b) Removes the first dimension from the right of the array
c) Removes the first dimension from the left of the array
d) Removes the last dimension from the left of the array



- Related Topics