Home » C++ Programming » Pointers » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class Car
    {
    public:
    int Lamborghini;
    int Audi;
    };
    int count_CarType(Car * begin, Car * end, int Car :: *CarType)
    {
    int count = 0;
    for (Car * iterator = begin; iterator != end; ++ iterator)
    count += iterator ->* CarType;
    return count;
    }
    int main()
    {
    Car CarArray[5] = {{ 4, 2 },{ 6, 1 }};
    cout << "I have " << count_CarType(CarArray, CarArray + 2, & Car :: Lamborghini) << " Lamborghini.\n";
    cout << "And I have " << count_CarType(CarArray, CarArray + 2, & Car :: Audi) << " Audi.";
    return 0;
    }
    1. I have 10 Lamborghini.
    2. And I have 3 Audi.
    3. I have 10 Lamborghini.
      And I have 3 Audi.
    4. And I have 3 Audi.
      I have 10 Lamborghini.
    5. None of these
Correct Option: C

In this program, We are passing the value to the class and adding the values and printing it in the main.



Your comments will be displayed only after manual approval.