Lecture7_8.bw - ECE 3090 Software for Engineering Systems...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: ECE 3090 Software for Engineering Systems Dr. Ayanna Howard School of Electrical and Computer Engineering Georgia Institute of Technology Lecture 7 - Pointers 2 Adapted from Brief Version of Starting Out with C++ Getting the Address of a Variable Each variable in program is stored at a unique address Use address operator & to get address of a variable: int num = -99; cout << # // prints address // in hexadecimal Pointer variable : Often just called a pointer, it's a variable that holds an address Because a pointer variable holds the address of another 2 Adapted from Brief Version of Starting Out with C++ Getting the Address of a Variable Each variable in program is stored at a unique address Use address operator & to get address of a variable: int num = -99; cout << # // prints address // in hexadecimal Pointer variable : Often just called a pointer, it's a variable that holds an address Because a pointer variable holds the address of another piece of data, it "points" to the data 3 Adapted from Brief Version of Starting Out with C++ Something Like Pointers: Arrays We have already worked with something similar to pointers, when we learned to pass arrays as arguments to functions. For example, suppose we use this statement to pass the array numbers to the showValues function: showValues(numbers, SIZE); 4 Adapted from Brief Version of Starting Out with C++ Something Like Pointers : Arrays The values parameter, in the showValues function, points to the numbers array. C++ automatically stores the address of numbers in the values parameter. 5 Adapted from Brief Version of Starting Out with C++ Something Like Pointers: Reference Variables We have also worked with something like pointers when we learned to use reference variables. Suppose we have this function: void getOrder(int &donuts) { cout << "How many doughnuts do you want? "; cin >> donuts; } And we call it with this code: int jellyDonuts; getOrder(jellyDonuts); 6 Adapted from Brief Version of Starting Out with C++ Something Like Pointers: Reference Variables The donuts parameter, in the getOrder function, points to the jellyDonuts variable. C++ automatically stores the address of jellyDonuts in the donuts parameter. 7 Adapted from Brief Version of Starting Out with C++ Pointer Variables Pointer variables are yet another way using a memory address to work with a piece of data. Pointers are more "low-level" than arrays and reference variables. This means you are responsible for finding the address you want to store in the pointer and correctly using it. 8 Adapted from Brief Version of Starting Out with C++ Pointer Variables Definition: int *intptr; Read as: intptr can hold the address of an int Spacing in definition does not matter: int * intptr; // same as above int* intptr; // same as above 9 Adapted from Brief Version of Starting Out with C++ Pointer Variables...
View Full Document

This note was uploaded on 06/09/2009 for the course ECE 3090 taught by Professor Staff during the Fall '08 term at Georgia Institute of Technology.

Page1 / 64

Lecture7_8.bw - ECE 3090 Software for Engineering Systems...

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

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