My Report

C++ String Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Pick the incorrect statement about Character-Array.

2. What is the identifier given to string class to declare string objects?

3. Which of the following is correct way of concatenating two string objects in C++?

way 1:
string s1 = "hello";
string s2 = "world";
string s3 = s1 + s2;

way 2:
string s1 = "hello";
string s2 = "world";
string s3 = s1.append(s2);

way 3:
string s1 = "hello";
string s2 = "world";
string s3 = strcat(s1,s2);

4. What is Character-Array?

5. Which header file is used to include the string object functions in C++?

6. What will be the output of the following C++ code?

#include <iostream> 
#include <string>
using namespace std; 
int main(int argc, char const *argv[])
{
	char s1[6] = "Hello";
	char s2[6] = "World";
	char s3[12] = s1 + " " + s2;
	cout<<s3;
	return 0;
}

7. What will be the output of the following C++ code if the string entered by the user is "Hello World"?

#include <iostream> 
#include <string>
using namespace std; 
int main(int argc, char const *argv[])
{
	string str;
	cin>>str;
	cout<<str;
	return 0;
}

8. Which function is used to get the length of a string object?

9. What is string objects in C++?

10. Pick the correct statement about string objects in C++.

11. What will be the output of the following C++ code?

#include <iostream> 
#include <string>
using namespace std; 
int main(int argc, char const *argv[])
{
	string str;
	cin>>str;
	cout<<str;
	return 0;
}

12. What will be the output of the following C++ code?

#include <iostream> 
#include <string>
using namespace std; 
int main(int argc, char const *argv[])
{
	string s1 = "Hello";
	string s2 = "World";
	string s3 = s1 + " " + s2;
	cout<<s3;
	return 0;
}

13. Which of the following is not a modifier function in string class?

14. What will be the output of the following C++ code?

#include <iostream> 
#include <string>
using namespace std; 
int main(int argc, char const *argv[])
{
	char str[] = "Hello World";
	cout<<str[0];
	return 0;
}

15. What will be the output of the following C++ code?

#include <iostream> 
#include <string>
using namespace std; 
int main(int argc, char const *argv[])
{
	char str[10];
	cin>>str;
	cout<<str;
	return 0;
}

 

Start practicing “1000 MCQs on C++”, and once you are ready, you can take tests on all topics by attempting our “C++ Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.