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
<[email protected]>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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to