The document provides an overview of pointers, explaining their purpose in accessing memory addresses, modifying function arguments, and creating data structures. It covers basic concepts, syntax, and the use of pointers with functions, strings, and objects, as well as the new and delete operators for memory management. Additionally, it includes a section for questions and discussions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
24 views
Lec 7 Pointers
The document provides an overview of pointers, explaining their purpose in accessing memory addresses, modifying function arguments, and creating data structures. It covers basic concepts, syntax, and the use of pointers with functions, strings, and objects, as well as the new and delete operators for memory management. Additionally, it includes a section for questions and discussions.
POINTERS AND FUNCTIONS • We can pass arguments to a function as: • By value void somefun(int param){ } int x = 8; somefun(x); • By reference void somefun(int& param){ } int x = 8; somefun(x); • By passing pointers void somefun(int∗ param){ } int x = 8; somefun(&x); POINTERS AND • STRINGS As strings are array of characters therefore we ca interpret them as pointers as below : char str1[] = ”Some constant string”; char* str2 = ”Some constant pointer string”; cout « str1 « endl; //Some constant string cout « str2 « endl; //Some constant pointer string cout « ++str2 « endl; //ome constant pointer string THE NEW AND DELETE OPERATORS • new Operator: a different approach to obtain blocks of memory • It obtains memory from operating system and returns a pointer to its starting point • We must release the memory assigned by new operator • Thus use the delete operator to release the memory POINTERS TO OBJECTS • Pointers can point simple data types and arrays but can also point to objects • Sometimes, however it is not known how many objects of a given class to create as hardcoded • In such cases, we can use new to create objects during program execution Questions? Subtitle goes Here