Arrays

1

What is the output of this program?

1.
    #include 
2.    
    using namespace std;
3.    
    int main()
4.    
    {
5.    
        int array[] = {10, 20, 30};
6.        
        cout << -2[array];
7.        
        return 0;
8.        
    }
A. -15
B. -30
C. compile time error
D. garbage value

2

What is the output of this program?

1.
    #include 
2.    
    using namespace std;
3.    
    int main()
4.    
    {
5.    
        char str[5] = "ABC";
6.        
        cout << str[3];
7.        
        cout << str;
8.        
        return 0;
9.        
    }
A. ABC
B. ABCD
C. AB
D. None of the mentioned

3

What is the output of this program?

1.
    #include 
2.    
    using namespace std;
3.    
    int main()
4.    
    {
5.    
        int a = 5, b = 10, c = 15;
6.        
        int arr[3] = {&a, &b, &c};
7.        
        cout << *arr[*arr[1] - 8];
8.        
        return 0;
9.        
    }
A. 15
B. 18
C. garbage value
D. compile time error

4

What will be the output of the this program?

1.
    #include 
2.    
    using namespace std;
3.    
    int main ()
4.    
    {
5.    
        int array[] = {0, 2, 4, 6, 7, 5, 3};
6.        
        int n, result = 0;
7.        
        for (n = 0; n < 8; n++) {
8.        
            result += array[n];
9.            
        }
10.        
        cout << result;
11.        
        return 0;
12.        
    }
A. 25
B. 26
C. 27
D. None of the mentioned

5

What will be the output of this program?

1.
    #include 
2.    
    using namespace std;
3.    
    int array1[] = {1200, 200, 2300, 1230, 1543};
4.    
    int array2[] = {12, 14, 16, 18, 20};
5.    
    int temp, result = 0;
6.    
    int main()
7.    
    {
8.    
        for (temp = 0; temp < 5; temp++) {
9.        
            result += array1[temp];
10.            
        }
11.        
        for (temp = 0; temp < 4; temp++) {
12.        
            result += array2[temp];
13.            
        }
14.        
        cout << result;
15.        
        return 0;
16.        
    }
A. 6553
B. 6533
C. 6522
D. 12200