#include<iostream>
using namespace std;
class base
       {
           public:
           int bval;
           base(){bval=0;}
       };
class deri:public base
       {
           public:
           int dval;
           deri(){dval=1;}
       };
void SomeFunc(base *arr,int size)
{
for(int i=0; i<size; i++,arr++)
{       cout<<arr->bval<<endl;
         cout<<&(arr->bval)<<endl;

}
cout<<endl;
}
int main()
{
base BaseArr[5];
SomeFunc(BaseArr,5);
deri DeriArr[5];
SomeFunc(DeriArr,5);
system("pause");
return 0;
}
see the output u will understant

On Sun, Aug 21, 2011 at 12:44 PM, Puneet Chawla
<puneetchawla...@gmail.com>wrote:

> Wil u please explain in context of o/p.means how 1 whn SomeFunc(DeriArr,5);
> stmt is executed how 0 and 1 will come..???
>
>
> On Sun, Aug 21, 2011 at 12:40 PM, Naman Mahor <naman.ma...@gmail.com>wrote:
>
>> because the pointer of base class will move by 2 bytes every time but the
>> size of derived class is 4 byte.
>>
>>
>> On Sun, Aug 21, 2011 at 12:31 PM, Puneet Chawla <
>> puneetchawla...@gmail.com> wrote:
>>
>>> class base
>>>        {
>>>            public:
>>>            int bval;
>>>            base(){bval=0;}
>>>        };
>>> class deri:public base
>>>        {
>>>            public:
>>>            int dval;
>>>            deri(){dval=1;}
>>>        };
>>> void SomeFunc(base *arr,int size)
>>> {
>>> for(int i=0; i<size; i++,arr++)
>>>        cout<<arr->bval;
>>> cout<<endl;
>>> }
>>> int main()
>>> {
>>> base BaseArr[5];
>>> SomeFunc(BaseArr,5);
>>> deri DeriArr[5];
>>> SomeFunc(DeriArr,5);
>>> system("pause");
>>> return 0;
>>> }
>>>
>>> 00000
>>> 01010
>>> Will somebody tell me why it's showing this..??
>>>
>>> --
>>> With regards
>>>   ............
>>> Puneet
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> With regards
>   ............
> Puneet
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to