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...

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

Announcement 1 another poll •please complete today's poll on moodle
Image of page 1
Cartoon of the Day 2 from
Image of page 2
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
Image of page 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
Image of page 4
Announcements VOTE! in federal election •October 21 Need a reason to vote? Check out or • - winnipeg-cancer-diagnosis-vote-1.5322201 5
Image of page 5
Clarification 6
Image of page 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
Image of page 7
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
Image of page 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
Image of page 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
Image of page 10
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
Image of page 11
On to today’s material … 12
Image of page 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
Image of page 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
Image of page 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
Image of page 15
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
Image of page 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]:
Image of page 17
Image of page 18

You've reached the end of your free preview.

Want to read all 72 pages?

  • Spring '14