• Tutorials
  • Courses
  • Tracks

String Data Structure Quiz for Beginners

Last Updated :
Discuss
Comments

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++
#// 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?

C++
#include <iostream>
using namespace std;

int main()
{

    string str = "GeeksForGeeks";
    cout << str.substr(2).substr(4);
    return 0;
}
  • eksForGeeks

  • ForGEeks

  • Geeks

  • orGeeks

Question 5

Which of the following is a palindromic string?

  • "APPLE"

  • "ABCDE"

  • "APPLA"

  • "ABCCBA"

Question 6

What is the time complexity to reverse a string?

  • O(n^2)

  • O(1)

  • O(log n)

  • O(n)

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?

C++
#include <iostream>
using namespace std;

int main() {

    cout << "GFG!"[0] <<" "<<"GFG!"[3] ;
    return 0;
}
  • Error

  • G !

  • F !

  • None

There are 20 questions to complete.

Take a part in the ongoing discussion