Arrays


  1. Which of the following accesses the ninth element stored in array?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    The array location starts from zero, So it can accessed by array[8].


  1. What will be the output of the this program?
    #include 
    using namespace std;
    int main ()
    {
    int arr[] = {10, 12, 40, 16, 70, 15, 30};
    int k, res = 0;
    for (k = 0; k < 5; k++) {
    res += arr[k];
    }
    cout << res;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    We are adding all the elements in the array and printing it. Total elements in the array is 5, but our for loop will go beyond 5 and add a garbage value.



  1. What will be the output of this program?
    #include 
    using namespace std;
    int arr1[] = {150, 50, 230, 130, 160};
    int arr2[] = {13, 15, 30, 28, 50};
    int temp, res = 0;
    int main()
    {
    for (temp = 0; temp < 5; temp++)
    {
    res += arr1[temp];
    }
    for (temp = 0; temp < 4; temp++)
    {
    res += arr2[temp];
    }
    cout << res;
    return 0;
    }












  1. View Hint View Answer Discuss in Forum

    None of these

    Correct Option: A

    In this program we are adding the every element of two arrays. Finally we got output as 806.


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    array;



  1. What is the index number of the last element of an array with 12 elements?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Because the first element always starts at 0. So it is on 11 position.