Question 1
What is the output of the following code?
#include <iostream>
using namespace std;
int main()
{
string str1 = "Hello";
string str2 = "Geeks";
string str3 = str1 + str2;
cout << str3 << endl;
return 0;
}
Hello + Geeks
str1 + str2
Hello Geeks
HelloGeeks
Question 2
What is the output of the following code?
#include <iostream>
using namespace std;
int main()
{
string str = "Hello";
cout << str.substr(2, 5);
return 0;
}
Syntax error
ello
llo
None
Question 3
What is the output of the following code?
#include<bits/stdc++.h>
using namespace std;
int main()
{
// Write C++ code here
char str_array2[] = "Geeks";
cout << sizeof(str_array2) << " ";
char str_array[] = { 'G', 'e', 'e', 'k', 's'};
cout << sizeof(str_array);
return 0;
}
6, 6
5, 6
6, 5
None
Question 5
How will you print "\\\n" on the screen?
cout << "\\\n";
cout<<"\\\\\n";
cout<<"//n";
cout<<"///n"
Question 6
What will the output of the following questions:
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a = "Hello";
string b = "World";
string c = b.append(a);
cout << c << endl;
return 0;
}
Hello world
World hello
WorldHello
Error
Question 7
What is missing in the given code?
#include <bits/stdc++.h>
using namespace std;
void reverseStr(string& str)
{
for (int i = 0; i < n / 2; i++)
swap(str[i], str[n - i - 1]);
}
// Driver program
int main()
{
string str = "geeksforgeeks";
reverseStr(str);
cout << str;
return 0;
}
swap function is not defined
string is not defined here.
Variable n is not declared anywhere.
None
Question 8
What is the function present to sort a string in C++?
sort();
sort(str.begin(), str.end());
Sort_asec();
None
Question 9
What is the below image explaining?
The image is about the substring of a string
The image is about the subsequence of a string
The image is about arrays.
None
Question 10
What is a palindromic string?
The string of length 0
The string of having a special character.
The string of having an uppercase letter
The string whose reversed string is equal to the original string.
There are 20 questions to complete.