Home » C++ Programming » Pointers » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class Lamborghini
    {
    public:
    int speed;
    };
    int main()
    {
    int Lamborghini :: *ptrSpeed = &Lamborghini :: speed;
    Lamborghini obj;
    obj.speed = 4;
    cout << obj.speed << endl;
    obj.*ptrSpeed = 5;
    cout << obj.speed << endl;
    return 0;
    }
    1. 4
    2. 5
    3. 5
      4
    4. 4
      5
    5. None of these
Correct Option: D

In this program, We are printing the value by direct access and another one by using pointer to member.



Your comments will be displayed only after manual approval.