05_Pointers_References_and_Arrays - Discussion 5: Pointers,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Discussion 5: Pointers, References, and Arrays EECS 280 Monday, October 10th, 2011 1 Introduction In C++, code dealing with pointers and references can be quite confusing. Consider the following code: 1 int a = 2; 2 int* b = &a; 3 int & c = *b; In it, the * and operators each appear twice, but have different effects in each case. The way these operators function is directly tied to the way memory is managed in C++. Once you understand the way they work, you can translate code into a diagram format that makes C++ variables more transparent. 2 Memory in C++ 2.1 Declaration Variable declaration in C++ follows the general form: Where the parts in brackets are optional. This is the same syntax is used in function arguments and return type. The symbol represents data of the specified type (e.g. int a or ). If the is present, then the symbol will refer to a preexisting piece of data — this is called assigning by reference. Without the , the symbol refers to a new piece of data in memory. The type can be basic (e.g. int or bool ), class (e.g. vector or string ), or struct (e.g. game or node ). In addition, you can make the type a pointer to another
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

05_Pointers_References_and_Arrays - Discussion 5: Pointers,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online