Lecture8 - ECE 3090 Software for Engineering Systems Prof...

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

View Full Document Right Arrow Icon
ECE 3090 Software for Engineering Systems Prof. Hongwei Wu School of Electrical and Computer Engineering Georgia Institute of Technology (Savannah)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Pointers ± ± Pointer variable ± Creating and using pointer variables ± Relationships between arrays and pointers ± Pointer Arithmetic ± Initializing Pointers ± Comparing Pointers ± Pointers as function parameters ± Pointers to constants ± Dynamic memory allocation ± Returning Pointers from Functions
Background image of page 2
Getting the address of a variable ± Each variable is allocated a section of memory that is large enough to hold the value of the variable’s data type. ± Each byte of memory has a unique address . ± A variable the address is the address of the first byte allocated to that variable. char letter; short number; float amount; letter number amount
Background image of page 3

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

View Full DocumentRight Arrow Icon
± To get the address allocated to a variable, use the cout << &number; // prints address in hexadecimal.
Background image of page 4
Pointer Variables ± A pointer variable , a.k.a pointer , is a special variable to hold a memory address. ± Because a pointer variable holds the address of another piece of data, it "points" to the data. ± Passing an array as an argument to a function Æ passing the array’s beginning address.
Background image of page 5

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

View Full DocumentRight Arrow Icon
const int SIZE = 5; int numbers[SIZE] = {1, 2, 3, 4, 5}; showValues(numbers, size); void showValues(int values[], int size) { for (int i=0; i < size; i++) cout << values[i] << endl; } The values parameter, in the showValues function, points to the numbers array. C++ automatically stores the address of numbers in the values parameter. Example
Background image of page 6
± Reference variable int jellyDonuts; getOrder(jellyDonuts); { cout << "How many doughnuts do you want: "; cin >> donuts; } The donuts parameter, in the
Background image of page 7

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

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

Page1 / 31

Lecture8 - ECE 3090 Software for Engineering Systems Prof...

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

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