CARVIEW |
String Data Structure Quiz for Beginners
Question 1
string a = "10";
string b = "20";
string c = a + b;
Guess the output:
"10 20"
30
10 20
1020
Question 2
What the below program will Print?
#// C program to find the length of string
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str = "Hello Geeks";
int i;
for (i = 0; str[i] != '\0'; ++i)
;
cout << i;
return 0;
}
0
1
5
11
Question 3
Which of these methods of class String is used to obtain the length of the String object?
get()
Sizeof()
lengthof()
length()
Question 4
What is the output of the below code?
#include <iostream>
using namespace std;
int main()
{
string str = "GeeksForGeeks";
cout << str.substr(2).substr(4);
return 0;
}
eksForGeeks
ForGEeks
Geeks
orGeeks
Question 7
Which of these methods from the String class is used to extract a single character from an object of String?
CHARAT()
charAt()
CharAt()
charAT()
Question 8
How does strcmp() function work to compare two strings?
It compares characters based on their index.
It compares strings based on the index.
It compares characters of the string based on their ASCII values.
None.
Question 9
Which of the following statement is a binary string?
"ab"
"121212"
"01010101110"
None
Question 10
What is the output of the following code?
#include <iostream>
using namespace std;
int main() {
cout << "GFG!"[0] <<" "<<"GFG!"[3] ;
return 0;
}
Error
G !
F !
None
There are 20 questions to complete.