Download presentation
Presentation is loading. Please wait.
1
16.216 ECE Application Programming
Instructor: Dr. Michael Geiger Spring 2014 Lecture 24 Exam 2 Preview
2
ECE Application Programming: Exam 2 Preview
Lecture outline Announcements/reminders Program 7 posted; due 4/9 Exam 2: Wednesday, 4/2 Allowed one 8.5” x 11” sheet of notes Today’s lecture: Exam 2 Preview 4/28/2018 ECE Application Programming: Exam 2 Preview
3
ECE Application Programming: Exam 2 Preview
Exam 2 notes Allowed one 8.5” x 11” double-sided note sheet No other notes No electronic devices (calculator, phone, etc.) Exam will last 50 minutes Covers all lectures after Exam 1 (13-22) except Friday’s lecture on file I/O Same general format as Exam 1 1 multiple choice 1 code reading 1 code writing (complete 2 of 3 parts; all 3 for extra credit) 4/28/2018 ECE Application Programming: Exam 2 Preview
4
ECE Application Programming: Exam 1 Preview
Review: for loops for (<init var>; <test>; <change var>) <statements> Operators to directly change variable x++, x-- post-increment/decrement ++x, --x pre-increment/decrement +=, -=, *=, /= augmented assignment 4/28/2018 ECE Application Programming: Exam 1 Preview
5
ECE Application Programming: Exam 2 Preview
Review: functions Used to break programs into smaller pieces Useful when code sequences repeated Functions have: An optional return value A name Optional arguments Must be prototyped or written completely prior to use Arguments can be: Passed by value: copy of argument is sent to function Arguments cannot be modified outside function Passed by address: address of argument Use pointers or address operator (&) Arguments can be modified outside function—used to “return” multiple values 4/28/2018 ECE Application Programming: Exam 2 Preview
6
ECE Application Programming: Exam 2 Preview
Review: pointers Pointer: address of a variable Can get address of existing object using & Can get value of existing pointer using * Can assign pointers of same type to each other Pointer declaration: <base type>* <pointer name> Base type determines how reference is interpreted Use pointers as function arguments pass by address 4/28/2018 ECE Application Programming: Exam 2 Preview
7
Review: arrays & pointers
Arrays: groups of data with same type x[10] has 10 elements, x[0] through x[9] Can also define with initial values e.g. double list[] = {1.2, 0.75, }; Must be sure to access inside bounds Array name is a pointer Arrays are always passed by address to functions Can use pointer to access array Can use arithmetic to move pointer through array We will not cover pointer arithmetic on this exam 4/28/2018 ECE Application Programming: Exam 2 Preview
8
ECE Application Programming: Exam 2 Preview
Review: 2D arrays Declared similarly to 1D arrays Example (see below): int x[3][4]; Index elements similarly to 1-D arrays Initialize: int y[3][4] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12} }; Typically used with nested for loops Can pass to functions—must specify # columns Col. 0 Col. 1 Col. 2 Col. 3 Row 0 x[0][0] x[0][1] x[0][2] x[0][3] Row 1 x[1][0] x[1][1] x[1][2] x[1][3] Row 2 x[2][0] x[2][1] x[2][2] x[2][3] 4/28/2018 ECE Application Programming: Exam 2 Preview
9
ECE Application Programming: Exam 2 Preview
Review: strings Represented as character arrays Can be initialized using string constants char hello[] = “Hello”; Can access individual elements hello[3] = ‘l’; Can print directly or with formatting Print directly: printf(hello); Print w/formatting using %s: printf(“%s\n”, hello); Must leave enough room for terminating ‘\0’ 4/28/2018 ECE Application Programming: Exam 2 Preview
10
Review: String functions
In <string.h> library: Copying strings: char *strcpy(char *dest, const char *source); char *strncpy(char *dest, const char *source, size_t num); Return dest Comparing strings: int strcmp(const char *s1, const char *s2); int strncmp(const char *s1, const char *s2, size_t num); Character-by-character comparison of character values Returns 0 if s1 == s2, 1 if s1 > s2, -1 if s1 < s2 4/28/2018 ECE Application Programming: Exam 2 Preview
11
Review: String functions (cont.)
Find # of characters in a string size_t strlen(const char *s1); Returns # characters before ‘\0’ Not necessarily size of array “Add” strings together—string concatenation char *strcat(char *dest, const char *source); char *strncat(char *dest, const char *source, size_t num); Returns dest 4/28/2018 ECE Application Programming: Exam 2 Preview
12
ECE Application Programming: Exam 2 Preview
Final notes Next time Exam 2—please be on time Reminders: Program 7 posted; due 4/9 Exam 2: Wednesday, 4/2 Allowed one 8.5” x 11” sheet of notes 4/28/2018 ECE Application Programming: Exam 2 Preview
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.