C++ interview questions part 56

C++ interview questions part 56

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. What is the output of the following C++ code? #include #include using namespace std; int main () { std::string str ("Sanfoundry."); str.back() = '!'; std::cout << str << endl; return 0; }

Correct Answer is : arr1.swap(arr2);

2. What is the output of the following C++ code? #include #include using namespace std; int main () { string str = "Sanfoundry!"; cout<
Correct Answer is : To check whether the size of an array is zero or not


3. Which is an instantiation of the basic_string class template?

Correct Answer is : To fill an array with a given single value

4. Which character is used to terminate the string?

Correct Answer is : 22222

5. Where are the strings stored?

Correct Answer is :

6. What will happen if a string is empty?

Correct Answer is : both f.assign({1,2,3,4,5}) and f.assign(10,5)

7. How many types of representation are in the string?

Correct Answer is : All of the mentioned

8. What is the header file for the string class?

Correct Answer is : forward_list f;

9. Which method do we use to append more than one character at a time?

Correct Answer is :

10. The data elements in the structure are also known as what?

Correct Answer is : all of the mentioned

11. What will be used when terminating a structure?

Correct Answer is : vectors do not have a function to access the last element

12. What will happen when the structure is declared?

Correct Answer is : begin() returns an iterator to first element whereas cbegin() returns constant iterator to first element

13. The declaration of the structure is also called as?

Correct Answer is : begin() returns an iterator to the first element and rbegin() returns an iterator to an element kept at the end of the vector

14. What will be the output of this program? #include using namespace std; int main() { struct ShoeType { string style; double price; }; ShoeType shoe1, shoe2; shoe1.style = "Adidas"; shoe1.price = 9.99; cout << shoe1.style << " $ "<< shoe1.price; shoe2 = shoe1; shoe2.price = shoe2.price / 9; cout << shoe2.style << " $ "<< shoe2.price; return 0; }

Correct Answer is : 3 2 3 4 5

15. Which of the following is a properly defined structure?

Correct Answer is : v.size()

16. Which of the following accesses a variable in structure *b?

Correct Answer is : v.capacity()

17. subscript operator is used to access which elements?

Correct Answer is : Vector doubles its capacity after it is full

18. What do we need to do to pointer for overloading the subscript operator?

Correct Answer is : 10

19. What do we need to use when we have multiple subscripts?

Correct Answer is : 50

20. What is meant by template parameter?

Correct Answer is : 4

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon