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:

  • A

    "10 20"

  • B

    30

  • C

    10 20

  • D

    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;
}
  • A

    0

  • B

    1

  • C

    5

  • D

    11

Question 3

Which of these methods of class String is used to obtain the length of the String object?

  • A

    get()

  • B

    Sizeof()

  • C

    lengthof()

  • D

    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;
}
  • A

    eksForGeeks

  • B

    ForGEeks

  • C

    Geeks

  • D

    orGeeks

Question 5

Which of the following is a palindromic string?

  • A

    "APPLE"

  • B

    "ABCDE"

  • C

    "APPLA"

  • D

    "ABCCBA"

Question 6

What is the time complexity to reverse a string?

  • A

    O(n^2)

  • B

    O(1)

  • C

    O(log n)

  • D

    O(n)

Question 7

Which of these methods from the String class is used to extract a single character from an object of String?

  • A

    CHARAT()

  • B

    charAt()

  • C

    CharAt()

  • D

    charAT()

Question 8

How does strcmp() function work to compare two strings?

  • A

    It compares characters based on their index.

  • B

    It compares strings based on the index.

  • C

    It compares characters of the string based on their ASCII values.

  • D

    None.

Question 9

Which of the following statement is a binary string?

  • A

    "ab"

  • B

    "121212"

  • C

    "01010101110"

  • D

    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;
}
  • A

    Error

  • B

    G !

  • C

    F !

  • D

    None

There are 20 questions to complete.

Take a part in the ongoing discussion