- 1、本文档共33页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
华中科技大学博士论文答辩会-M.MuNeeBReHmaN
Pointers to Pointers C++ allows the use of pointers that point to pointers, that these, in its turn, point to data (or even to other pointers). char a; char *b; char **c; a = z; b = a; c = b; cout**c; Pointer to string constant Syntax: char * string Literal void main() { char str1[] = “Defined as an array”; char* str2 = “Defined as a pointer”; cout str1 endl; cout str2 endl; //str1++; // can’t do this; str1 is a constant str2++; // this is ok, str2 is a pointer cout str2 endl; // efined as a pointer } Pointer to string constant // Copying string using Pointers void main() { char* str1 = “Self-conquest is the greatest victory.”; char str2[80]; //empty string char* src = str1; char* dest = str2; while( *src ) //until null character, *dest++ = *src++; //copy chars from src to dest *dest = ‘\0’; //terminate dest cout str2 endl; //display str2 } Computer Programming Computer Programming Pointers Objectives To describe what a pointer is To learn how to declare a pointer and assign a value to it To access elements via pointers To pass arguments by reference with pointers To understand the relationship between arrays and pointers To know how to access array elements using pointers To declare constant pointers and constant data Introduction to Pointers Pointer variables, simply called pointers, are designed to hold memory addresses as their values Normally, a variable contains a specific value, e.g., an integer, a floating-point value, and a character However, a pointer contains the memory address of a variable that in turn contains a specific value Introducing Pointers When we declare a variable, some memory is allocated for it. Thus, we have two properties for any variable: Its Address and Its Data value For Example, int count = 5; Introducing Pointers How to get the memory-address of a variable? Address of a variable can be accessed thr
文档评论(0)