C函数、数组、指针和调试器gdb--指针

C函数、数组、指针和调试器gdb--指针

ID:41393824

大小:76.28 KB

页数:32页

时间:2019-08-24

C函数、数组、指针和调试器gdb--指针_第1页
C函数、数组、指针和调试器gdb--指针_第2页
C函数、数组、指针和调试器gdb--指针_第3页
C函数、数组、指针和调试器gdb--指针_第4页
C函数、数组、指针和调试器gdb--指针_第5页
资源描述:

《C函数、数组、指针和调试器gdb--指针》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、C函数、数组、指针和调试器gdb—指针Thatexplicitlyindicatesthatthecurrentpointerdoesnotpointtoanyvariable・Forpointers,therearetwooperatorsassociatedwiththem,asfollows・&takeaddressoperator・*:takethevalueofthememorycellpointedtobythepointer・Theuseofpointers4to8cases#ineludeInt,main(

2、)Inta=100,B=200;Int*pl二&a,*p2=&b;Printf(〃%d〃,〃%d〃,〃a〃,〃B〃);Printf(〃%d〃,〃%d〃,〃*pl〃,‘'*p2〃);Printf(〃%x〃,〃%x〃,〃&b〃);Printf(〃%x〃,〃%x〃,〃P1〃,〃卩2〃);*pl=*pl*3;Printf(〃%d〃,a);Printf(〃%drT,*pl);Printf(〃%x〃,&a);Printf(〃%x〃,Pl);Pl二&b;Printf(〃%x〃,Pl);Printf(〃%x

3、〃,P2);Return0;}Theprogramrunsasfollows:OnehundredthousandandtwohundredOnehundredthousandandtwohundredBff59be0,bff59bdcBff59be0,bff59bdcThreehundredThreehundredBff59be0Bff59be0Bff59bdcBff59bdcProgramdescription:(1)theprogramfirstdefinestwopointers,Pl,P2,respectively,pointin

4、gtovariablesAandB.Thefirst,secondlinesoftheprogramoutputarethesamebecausethevaluesobtainedby*Pland*P2arethevaluesofthevariablestheypointto.(2)thethirdlineisthattheyoutputthevariablea,B'saddressinsixteendecimalform,andthefourthlineoutputsthevaluesofpointervariablesPl,p2・Var

5、iablePl,P2storestheaddressofthevariabletheyarepointingto.Plstoresthememoryaddressofthevariablea,andtheP2storesthememoryaddressofthevariableB.Thus,theresultsofthethirdand4stalksarethesame・(3)statement*Pl二*P1*3,firstobtainthepointerPlreferstothevariablevalue,thatis,100,after

6、3,theresultsaresavedtothePlpointofthevariable,atthistimethevariableavaluefrom100to300.Therefore,theprogramsixth,7linesoutput300.Thenexttwovariables,theaddressoftheAandthevalueofthePl,areprintedout,andthetwovaluesarethesameasthosewithouttheexecutionof*Pl二*Pl*3statements・(4)

7、thestatementPl二B,theaddressofthevariableBtothepointervariablePl,thenPlandP2pointtothevariableB,thetwopointervariabledhwyisavariableBmemoryaddress,theprogramoutputisconsistentwiththelasttwolines・Three,pointersandarraysInC,pointersarecloselyrelatedtoarrays.Thearraynameisactu

8、allythepointertothefirstelementofthearray.Seetheprogrambelow:Inta[]二{2,4,6,&10};Int*pl二a;

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。