Arrays


  1. What is the output of this program?
    #include 
    using namespace std;
    int main()
    {
    int arr[] = {15, 25, 50};
    cout << -2[arr];
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    It’s just printing the negative value of the concern element.


  1. What is the output of this program?
    #include 
    using namespace std;
    int main()
    {
    char str[20] = "Interview Mania";
    cout << str[10];
    cout <<" "<< str;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    We are just printing the values of first 10 values.



  1. What is the output of this program?
    #include 
    using namespace std;
    int main()
    {
    int p = 15, q = 11, r = 12;
    int array[3] = {&p, &q, &r};
    cout << *array[*array[1] - 8];
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    The conversion is invalid in this array. So it will arise error. The following compilation error will be raised:
    cannot convert from ‘int *’ to ‘int’

    In function 'int main()':
    6:35: error: invalid conversion from 'int*' to 'int' [-fpermissive]
    6:35: error: invalid conversion from 'int*' to 'int' [-fpermissive]
    6:35: error: invalid conversion from 'int*' to 'int' [-fpermissive]
    7:9: error: 'cout' was not declared in this scope
    7:32: error: invalid type argument of unary '*' (have 'int')


  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.