A
Aarti
Hi,
Can some one please explain why the output of this program is 15
#include <iostream>
using namespace std;
class A
{
public:
A():i(1)
{}
int i;
};
class B: public A
{
public:
B():j(2)
{}
int j;
};
int f(A* p, int count)
{
int total = 0;
for(int i=0; i<count; ++i)
{
total+=p++->i;
}
return(total);
}
int main()
{
B b[11];
cout << f(b,10);
return 0;
}
Regards,
Can some one please explain why the output of this program is 15
#include <iostream>
using namespace std;
class A
{
public:
A():i(1)
{}
int i;
};
class B: public A
{
public:
B():j(2)
{}
int j;
};
int f(A* p, int count)
{
int total = 0;
for(int i=0; i<count; ++i)
{
total+=p++->i;
}
return(total);
}
int main()
{
B b[11];
cout << f(b,10);
return 0;
}
Regards,