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

Đăng Khánh

New member
What will be the output of the following C++ code?
Code:
    #include  <iostream>
    using namespace std;
    int main()
    {
        double arr[] = {5.0, 6.0, 7.0, 8.0};
        double *p = (arr+2);
        cout << *p << endl;   
        cout << arr << endl;  
        cout << *(arr+3) << endl;
        cout << *(arr) << endl;  
        cout << *arr+9 << endl;  
        return 0;
    }
A.
7
0xbf99fc98
8
5
14
B.
7
8
0xbf99fc98
5
14
C. 0xbf99fc98
D. 14
 
Answer: a
Explanation: In this program, We are printing the values that are pointed by pointer and also the dereference operator.
Output:
Code:
$ g++ def5.cpp
$ a.out
7
0xbf99fc98
8
5
14
 

Tìm kiếm

Back
Top