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

Hương Trang

New member
What will be the output of the following C++ code?
Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        int i;
        char c;
        void *data;
        i = 2;
        c = 'd';
        data = &i;
        cout << "the data points to the integer value" << data;
        data = &c;
        cout << "the data now points to the character" << data;
        return 0;
    }
A. 2d
B. two memory addresses
C. 3d
D. 4d
 
Answer: b
Explanation: Because the data points to the address value of the variables only, So it is printing the memory address of these two variable.
Output:
Code:
$ g++ poi2.cpp
$ a.out
the data points to the integer value0xbfc81824 the data now points to the character0xbfc8182f
 

Tìm kiếm

Back
Top