2019.10.17_revised.pdf - Announcement ‣ another poll •please complete today's poll on moodle 1 Cartoon of the Day from https/xkcd.com/138 2

# 2019.10.17_revised.pdf - Announcement ‣ another poll...

• 72

This preview shows page 1 - 18 out of 72 pages.

Announcement 1 another poll •please complete today's poll on moodle
Cartoon of the Day 2 from
Announcements out-of-class midterm exam •17:30 (5:30 p.m.) – 19:00 (7:00 p.m.) on Monday, October 28, 2019 •HLTH E1150 •multiple-choice, closed-book exam 3
Announcements BarCamp •"ad-hoc unconference born from the desire for people to share and learn in an open environment" •Saturday, October 19th from 1pm-8pm •Atrium at Innovation Place •more information at 444800262984348/ 4
Announcements VOTE! in federal election •October 21 Need a reason to vote? Check out or • - winnipeg-cancer-diagnosis-vote-1.5322201 5
Clarification 6
& is "address of" operator a pair of statements often occurs •declaration and initialization of variable int i = 0; •declaration and initialization of a pointer variable (a pointer to the preceding variable) int * iPtr; iPtr = &i; // could be written as int *iPtr=&i; // or int* iPtr=&i; Referencing 7 iPtr: i: 0
Interpretation of * interpretation of * depends on where it occurs in an Rvalue as a binary operator, it means multiplication in an Rvalue as a unary operator it means "return the value of the memory location specified by this pointer" - e.g. printf( "The value = %d\n", *iPtr ); 8
Interpretation of * interpretation of * depends on where it occurs •in definition or declaration, it is an operator denoting "pointer to type" - e.g. int * iPtr; - same as int* iPtr; or int *iPtr; 9
Interpretation of * interpretation of * depends on where it occurs in an Lvalue , operator denotes "the memory location specified by the contents of this variable" - e.g. int i = 35; int * iPtr; iPtr = &i; *iPtr = 27; - value of i changed to 27 ! - see example_28.c and example_28_log.txt 10 iPtr: i: 27
Pointers highlights of example_29.c and example_29_log.txt note that ++ and * have the same precedence, and associate right-to-left - expression ++*iPtr is ++(*Ptr) - expression *iPtr++ is *(iPtr++) in our example, we want (*iPtr)++ - expression *(iPtr++) is different! 11
On to today’s material … 12
Arrays and Vectors simple case: single-dimension arrays (vectors) of atomic data types atomic data type – any default data type ( int , float , char , etc.) arrays are allocations of contiguous storage •solid block of memory •no interruptions 13
Arrays and Vectors form of declaration type arrayName[numberOfElements] name of the array is a synonym for the address of the start of the array type pointer-to-type elements of the array are of type type 14
Arrays and Vectors e.g. #define NUM_ELEMENTS 4 ... int ai[NUM_ELEMENTS]; 15 ai int -sized type of ai is int * value of ai is a constant
Arrays and Vectors usually specify an element of an array using notation of the form arrayName[indexOfElement ] indexing starts at 0 last element is arrayName[numberOfElements-1 ] 16
Arrays and Vectors e.g. element 2 of array ai (counting from 0) ai[2] is an int •the number of elements is 4, so the last element is ai[3] 17 ai[2]:

#### You've reached the end of your free preview.

Want to read all 72 pages?

• Spring '14