My Report

C++ Array Test – 1


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What is the correct definition of an array?

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

3. What will be the output of the following C++ code?

    #include <stdio.h>
    #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;
    } 

4. What will be the output of the following C++ code?

    #include <stdio.h>
    #include <iostream>
    using namespace std;
    int main()
    {
        char str[5] = "ABC";
        cout << str[3];
        cout << str;
        return 0;
    }

5. 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;
    }

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

7. 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;
    }

8. Which of the following correctly declares an array?

9. 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;
    } 

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


 

Start practicing “1000 MCQs on C++”, and once you are ready, you can take tests on all topics by attempting our “C++ Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.