Pointer compatibility issues:
- A const pointer cannot be assigned a value to a non-const pointer.
- A non-const pointer can be assigned to a const pointer, but only if it is an indirect operation
1 Example:2 int*pt1;3 Const*pt2;4 Const**PT3;5 6PT2=PT1;//OK7Pt1=pt2;//NO8pt3=&pt2;//OK9pt3=&pt1;//NO Double indirectionTen problem: OnePt1=pt2;//NO Apt3=&pt2;//OK -pt3=&pt1;//NO Double indirection - the Explain: - Constn=5; -INT *P1; -Constint**P2; + //consumption p2=&p1; is right -p2=&P1; +*p2=&n;//OK, but this mean p1=&n; A*p1=Ten;//OK because P1 isn't const, but that'll be contradicted with consumption
Pointer compatibility issues: Const pointers cannot be assigned to non-const pointers. A non-const pointer can be assigned to a const pointer, but only if it is a layer of indirect operation Example:int *PT1; Const *PT2; Const **PT3; Pt2=pt1;//ok pt1=pt2;//no pt3=&pt2;//ok pt3=&pt1;//no double indirection problem:pt1=pt2;//no p T3=&pt2;//ok pt3=&pt1;//no double indirection explain:const n=5; Int *p1; Const int **p2; Consumption p2=&p1; is Right p2=&p1; *p2=&n;//ok, but this mean p1=&n; *p1=10;//ok because P1 isn't const, but that'll be contradicted with consumption
C pointer compatibility issues