Loading...

C++ Multiple Choice Questions

Our C++ questions and answers focuses on all areas of C++ programming language covering 100+ topics in C++

C++ Arrays & Strings MCQ | Set 1

C++ Arrays & Strings | Set 1


1. Which of the following correctly declares an array?

a) int array[10];
b) int array;
c) array{10};
d) array array[10];



2. What is the index number of the last element of an array with 9 elements?

a) 9
b) 8
c) 0
d) Programmer-defined



3. What is the correct definition of an array?

a) An array is a series of elements of the same type in contiguous memory locations
b) An array is a series of element
c) An array is a series of elements of the same type placed in non-contiguous memory locations
d) An array is an element of the different type



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

a) array[0];
b) array[1];
c) array(2);
d) array;



5. What will be the output of the following C++ code?
#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;
}

a) 6553
b) 6533
c) 6522
d) 12200



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

a) array[6];
b) array[7];
c) array(7);
d) array;



7. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {

    int array[] = {0, 2, 4, 6, 7, 5, 3};
    int n, result = 0;
    for (n = 0; n < 8; n++){
        result += array[n];
    }
    cout << result;
    
    return 0;
}

a) 25
b) 26
c) 27
d) 21



8. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {

    int a = 5, b = 10, c = 15;
    int arr[3] = {&a, &b, &c};
    cout << *arr[*arr[1] - 0];
    
    return 0;
}

a) 15
b) 18
c) garbage value
d) compile time error



9. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {

    char str[5] = "ABC";
    cout << str [3];
    cout << str;
    
    return 0;
}

a) ABC
b) ABCD
c) AB
d) AC



10. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {

    char array[] = [10, 20, 30];
    cout << -2 [array];

    return 0;
}

a) -15
b) -30
c) compile time error
d) garbage value



- Related Topics