Vidyalelo
C++ Programming · all questions

Arrays and Strings in C++
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

72

Questions

3/4

Page

Pick an option on a question to see the right answer and solution.

How do you access the element at the second row and third column of a two-dimensional array named 'matrix' in C++?

Select an option to see the answer and solution.

Which of the following is true regarding the declaration of a string in C++ using the char array?

Select an option to see the answer and solution.

Which is an instantiation of the basic_string class template?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
    string str="Steve Jobs founded the apple";
    string str2 = str.substr (6, 4);
    unsigned pos = str.find("the");
    string str3 = str.substr (pos);
    cout << str2 << ' ' << str3 << '\n';
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int a = 5, b = 10, c = 15;
    int arr[3] = {&a, &b, &c};
    cout << *arr[*arr[1] - 8];
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
    string str ("Steve jobs");
    cout << str.length();
    return 0;
}

Select an option to see the answer and solution.

What will happen if a string is empty?

Select an option to see the answer and solution.

How many parameters can a resize method take?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
    int array[] = {10, 20, 30};
    cout << -2[array];
    return 0;
}

Select an option to see the answer and solution.

What is the difference between unsigned int length() and unsigned int size()?

Select an option to see the answer and solution.

How does the strings are stored in the memory?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <stdio.h>
#include<iostream>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
{
    for (temp = 0; temp < 5; temp++) 
    {
        result += array1[temp];
    }
    for (temp = 0; temp < 4; temp++)
    {
        result += array2[temp];
    }
    cout << result;
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
    string str ("Steve jobs");
    cout << str.capacity() << "\n";
    return 0;
}

Select an option to see the answer and solution.

How many maximum number of parameters does a string constructor can take?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
    string str;
    string str2="Steve jobs";
    string str3="He founded apple";
    str.append(str2);
    str.append(str3, 6, 3);
    str.append(str3.begin() + 6, str3.end());
    str.append(5,0x2e);
    cout << str << '\n';
    return 0;
}

Select an option to see the answer and solution.

Which of the following accesses the seventh element stored in array?

Select an option to see the answer and solution.

What is the correct definition of an array?

Select an option to see the answer and solution.

Which of the following gives the memory address of the first element in array?

Select an option to see the answer and solution.

Which character is used to terminate the string?

Select an option to see the answer and solution.

Where are the strings stored?

Select an option to see the answer and solution.