si***********@gmail.com wrote:
how i can improve my programming skill in pointer using c++
Go find the answers to these questions.
struct A { int a; };
struct B : A { int b; };
A xa[ 10 ];
B xb[ 10 ];
A * pa = xb;
// Q1 - what is the value of pa pointing to ?
A * pBAD = pa + 1;
// Q2 - why is pBAD, bad ?
B * pb = xb;
// - same as Q1
A * paOK = pb + 1;
// Q3 - what does paOK point to ?
A (&( * pf )( int * ))[ 10 ];
// Q4 - what is pf ?
A * paX = & pb[1];
bool b( paX == paOK );
// Q5 - what is the value of b
A * paY = & pb[3];
int iNOTGOOD( paY - paX );
// Q6 - Why is iNOTGOOD not good ?
A * paM = new B;
int main()
{
delete paM; // line Z - NOT GOOD
// Q7 - why is line Z a bad thing ?
paM = 0;
// Q8 - what is paM now ?
delete paM;
// Q9 - what does delete paM do ?
bool x( & (* xb).b == & xb->b );
// Q10 - What is the value of x ?
}
B * F()
{
B x[2];
return x; // doh !
// Q11 - Why is the line marked "doh" broken ?
}