《(7.6)--7.6Secondarypointer.pdf》由会员分享,可在线阅读,更多相关《(7.6)--7.6Secondarypointer.pdf(6页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Secondary pointerSecondary pointer7.6We have learned about the pointers that point to the memory in which the datastored are non-pointer type.Such a pointer is called a first level pointer.Pointer variable is also a type of variable,which means after defining a pointervariable,system memory is also
2、allocated for storing it.Thus,we can define anotherpointer to the memory corresponding to the first level pointer variable,which is calledthe secondary pointer,or pointer to pointer.Secondary pointer7.6The definition syntax for a secondary pointer variable is:DataType*VariableName;For example:int*pi
3、nt*pp=&p;Secondary pointer7.6EgUsing secondary pointerint main()int i,j,a2=1,2,3,4,5,6;int*p3;int*pp;for(i=0;i3;i+)pi=ai;/Equivalent to pi=&ai0;pp=p;/Equivalent to pp=&p0;Secondary pointer7.6EgUsing secondary pointerfor(i=0;i3;i+)for(j=0;j2;j+)cout*(*(pp+i)+j);/Equivalent to coutppij coutendl;return 0;Secondary pointer7.6Memory data of pp(Stores the starting address of p,i.e.the address of the first element of p)Memory data of p(Each cell represents an address,i.e.the starting address of element ai0)Memory data of a(Each cell represents 4 bytes)123456a00a01a10a11a20a21p0p1p2+0+1+2