Question? Leave a message!




C/C++ Programming

C/C++ Programming
CIS 190: C/C++ Programming Lecture 2 Not So Basics 1 Outline • Separate Compilation • Structures • define • Pointers – Passing by Value vs. Passing by Reference – Pointers and Arrays and Functions and Structs • Makefiles • Testing • Homework 2 What is Separate Compilation 3 Why Use Separate Compilation • organize code into collections of smaller files that can be compiled individually • can separate based on: – a usermade “library” (e.g., math functions) – related tasks (e.g., functions for handling a data structure) – subparts of the program (e.g., reading user input) 4 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() ... void PrintTrain(...) ... void AddTrainCar(...) ... hw2.c 5 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 6 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 7 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 8 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 9 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 10 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 11 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 12 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 13 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... void PrintTrain(...) ... void AddTrainCar(...) ... trains.c hw2.c 14 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... hw2.c void PrintTrain(...) ... void AddTrainCar(...) ... trains.c 15 Example: Homework 2 Files void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... include “trains.h” hw2.c void PrintTrain(...) ... void AddTrainCar(...) ... trains.c 16 Example: Homework 2 Files include “trains.h” void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... include “trains.h” hw2.c void PrintTrain(...) ... void AddTrainCar(...) ... trains.c 17 Example: Homework 2 Files include “trains.h” void PrintTrain(...); void AddTrainCar(...); int main() trains.h ... include “trains.h” hw2.c void PrintTrain(...) ... void AddTrainCar(...) ... trains.c 18 Separate Compilation • need to include “fileName.h” at top of any .c file using the functions prototypes inside that .h file • for local files we use quotes “filename.h” • for libraries we use carats stdio.h 19 Separate Compilation • after a program is broken into multiple files, the individual files must be: – compiled separately • using gcc and the –c flag – linked together • using gcc and the created .o (object) files 20 Compiling Multiple .c Files include “trains.h” int main() ... hw2.c include “trains.h” void PrintTrain(...) ... void AddTrainCar(...) ... trains.c void PrintTrain(...); void AddTrainCar(...); trains.h 21 Compiling Multiple .c Files include “trains.h” int main() ... hw2.c include “trains.h” void PrintTrain(...) ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c void PrintTrain(...); void AddTrainCar(...); trains.h 22 Compiling Multiple .c Files include “trains.h” tells the compiler we’re int main() compiling separately ... hw2.c – stops before linking include “trains.h” – won’t throw an error if void PrintTrain(...) everything’s not available ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c void PrintTrain(...); void AddTrainCar(...); trains.h 23 Compiling Multiple .c Files include “trains.h” int main() ... hw2.c include “trains.h” void PrintTrain(...) ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c void PrintTrain(...); void AddTrainCar(...); trains.h 24 Compiling Multiple .c Files include “trains.h” OBJECT FILE hw2.o int main() ... hw2.c include “trains.h” void PrintTrain(...) ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c void PrintTrain(...); void AddTrainCar(...); trains.h 25 Compiling Multiple .c Files include “trains.h” OBJECT FILE hw2.o int main() ... hw2.c include “trains.h” void PrintTrain(...) ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c void PrintTrain(...); void AddTrainCar(...); trains.h 26 Compiling Multiple .c Files include “trains.h” OBJECT FILE hw2.o int main() ... hw2.c include “trains.h” void PrintTrain(...) ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c gcc –c –Wall trains.c void PrintTrain(...); void AddTrainCar(...); trains.h 27 Compiling Multiple .c Files include “trains.h” OBJECT FILE hw2.o int main() ... hw2.c include “trains.h” void PrintTrain(...) ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c gcc –c –Wall trains.c void PrintTrain(...); void AddTrainCar(...); trains.h 28 Compiling Multiple .c Files include “trains.h” OBJECT FILE hw2.o int main() ... OBJECT FILE hw2.c trains.o include “trains.h” void PrintTrain(...) ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c gcc –c –Wall trains.c void PrintTrain(...); void AddTrainCar(...); trains.h 29 Compiling Multiple .c Files include “trains.h” OBJECT FILE hw2.o int main() ... OBJECT FILE hw2.c trains.o include “trains.h” void PrintTrain(...) ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c gcc –c –Wall trains.c void PrintTrain(...); void AddTrainCar(...); trains.h 30 Linking Multiple .o Files include “trains.h” OBJECT FILE hw2.o int main() ... OBJECT FILE hw2.c trains.o include “trains.h” void PrintTrain(...) ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c gcc –c –Wall trains.c void PrintTrain(...); void AddTrainCar(...); gcc –Wall hw2.o trains.o trains.h 31 Linking Multiple .o Files include “trains.h” OBJECT FILE hw2.o int main() ... OBJECT FILE hw2.c trains.o include “trains.h” void PrintTrain(...) ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c gcc –c –Wall trains.c void PrintTrain(...); void AddTrainCar(...); gcc –Wall hw2.o trains.o trains.h 32 Linking Multiple .o Files include “trains.h” OBJECT FILE hw2.o int main() ... OBJECT FILE hw2.c trains.o include “trains.h” EXECUTABLE a.out void PrintTrain(...) ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c gcc –c –Wall trains.c void PrintTrain(...); void AddTrainCar(...); gcc –Wall hw2.o trains.o trains.h 33 Linking Multiple .o Files include “trains.h” OBJECT FILE hw2.o int main() ... OBJECT FILE hw2.c trains.o include “trains.h” EXECUTABLE a.out void PrintTrain(...) ... void AddTrainCar(...) ... trains.c gcc –c –Wall hw2.c gcc –c –Wall trains.c void PrintTrain(...); void AddTrainCar(...); gcc –Wall hw2.o trains.o trains.h 34 Naming Executables • if you’d prefer to name the executable something other than a.out, use the o flag gcc –Wall hw2.o trains.o becomes gcc –Wall hw2.o trains.o –o hw2 name of the • and to run it, you just type executable ./hw2 35 Common Mistakes • Do not: • use include for .c files include “trains.c” – NO • use include inside a .h file • Do be conservative: • only include those files whose function prototypes are needed 36 Common Error Message • if you receive this error: “undefined reference to ‘fxnName’” • the linker can’t find a function called fxnName • 99 of the time, this is because fxnName was spelled wrong – could be in the definition/prototype or one of the times the function is called 37 Outline • Separate Compilation • Structures • define • Pointers – Passing by Value vs. Passing by Reference – Pointers and Arrays and Functions and Structs • Makefiles • Testing • Homework 38 Structures • collection of variables under one name – member variables can be of different types • use structures (or structs) – to keep related data together – to pass fewer arguments 39 An Example • an example structure that represents a CIS class, which has the following member variables: – an integer variable for the class number – string variables for the room and class title struct cisClass int classNum; char room 20; char title 30; ; 40 Example Structures • point in 3dimensional space • mailing address • student information 41 Example Structures • for reference: struct structName varType1 varName1; varType2 varName2; ... varTypeN varNameN; ; 42 Using Structs • to declare a variable of type struct cisClass: struct cisClass cis190; • to access a struct’s members, use dot notation: 43 Using Structs • to declare a variable of type struct cisClass: struct cisClass cis190; • to access a struct’s members, use dot notation: cis190 name of struct 44 Using Structs • to declare a variable of type struct cisClass: struct cisClass cis190; • to access a struct’s members, use dot notation: cis190. name of struct dot notation 45 Using Structs • to declare a variable of type struct cisClass: struct cisClass cis190; • to access a struct’s members, use dot notation: cis190.classNum name of name of variable struct inside struct dot notation 46 Using Structs • to declare a variable of type struct cisClass: struct cisClass cis190; • to access a struct’s members, use dot notation: cis190.classNum = 190; name of name of variable struct inside struct dot notation 47 Using Structs • when using printf: printf(“class : d\n”, cis190.classNum); • when using scanf: scanf(“d”, (cis190.classNum) ); − the parentheses are not necessary, but make it clear exactly what we want to happen in the code 48 typedefs • typedef declares an alias for a type typedef unsigned char BYTE; • allows you to refer to a variable by its shorter typedef, instead of the full name unsigned char b1; vs BYTE b2; 49 Using typedefs with Structs • can use it to simplify struct types: struct cisClass int classNum; char room 20; char title 30; ; 50 Using typedefs with Structs • can use it to simplify struct types: typedef struct cisClass int classNum; char room 20; char title 30; CISCLASS; • so to declare a struct, the code is now just CISCLASS cis190; 51 Structs as Variables • we can treat structs as variables (mostly) – pass to functions – return from functions – create arrays of structs – and more • but we cannot: – assign one struct to another using the = operator – compare structs using the == operator 52 Arrays of Structures CISCLASS classes 4; classNum classNum classNum classNum room room room room title title title title 0 1 2 3 53 Arrays of Structures CISCLASS classes 4; classNum classNum classNum classNum room room room room title title title title 0 1 2 3 • access like you would any array: 54 Arrays of Structures CISCLASS classes 4; classNum classNum classNum classNum room room room room title title title title 0 1 2 3 • access like you would any array: classes0 element of array to access 55 Arrays of Structures CISCLASS classes 4; classNum classNum classNum classNum room room room room title title title title 0 1 2 3 • access like you would any array: classes0.classNum = 190; dot notation variable element of array to access 56 Outline • Separate Compilation • Structures • define • Pointers – Passing by Value vs. Passing by Reference – Pointers and Arrays and Functions and Structs • Makefiles • Testing • Homework 57 define • C’s way of creating symbolic constants define NUMCLASSES 4 • use define to avoid “magic numbers” – numbers used directly in code • the compiler replaces all constants at compile time, so anywhere that the code contains NUMCLASSES it becomes 4 at compile time 58 define • use them the same way you would a variable define NUMCLASSES 4 define MAXSTUDENTS 30 define DEPARTMENT “CIS” CISCLASS classes NUMCLASSES; printf(“There are d students allowed in s department minicourses.\n”, MAXSTUDENTS, DEPARTMENT); 59 Using define • define does not take a type – or a semicolon • type is determined based on value given define FOO 42 – integer define BAR 42.0 – double define HW “hello” – string 60 Outline • Separate Compilation • Structures • define • Pointers – Passing by Value vs. Passing by Reference – Pointers and Arrays and Functions and Structs • Makefiles • Testing • Homework 61 Pointers • used to “point” to locations in memory int x; int xPtr; x = 5; xPtr = x; / xPtr points to x / xPtr = 6; / x’s value is 6 now / • pointer type must match the type of the variable whose location in memory it points to 62 Using Pointers with scanf • remember from last class that scanf uses a pointer for most variable types − because it needs to know where to store the values it reads in scanf(“d”, intvar); scanf(“f”, floatvar); • remember also that this isn’t true for strings: scanf(“s”, stringvar); 63 Ampersands Asterisks • pointers make use of two different symbols – ampersand – asterisk • ampersand – returns the address of a variable • asterisk – dereferences a pointer to get to its value 64 Pointers – Ampersand • ampersand returns the address of a variable int x = 5; int varPtr = x; int y = 7; scanf(“d d”, x, y); 65 Pointers – Asterisk • asterisk dereferences a pointer to get to its value int x = 5; int varPtr = x; int y = varPtr; 66 Pointers – Asterisk • asterisk dereferences a pointer to get to its value int x = 5; int varPtr = x; int y = varPtr; • asterisk is also used when initially declaring a pointer (and in function prototypes) 67 Pointers – Asterisk • asterisk dereferences a pointer to get to its value int x = 5; int varPtr = x; int y = varPtr; • asterisk is also used when initially declaring a pointer (and in function prototypes), but after declaration the asterisk is not used: varPtr = y; 68 Examples – Ampersand Asterisk int x = 5; int xPtr; used to declare ptr xPtr = x; used to get address but note is not used xPtr = 10; used to get value scanf(“d”,x); use for address 69 Visualization of pointers variable name memory address value 70 Visualization of pointers int x = 5; x variable name 0x7f96c memory address 5 value 71 Visualization of pointers int x = 5; int xPtr = x; x xPtr variable name 0x7f96c 0x7f960 memory address 5 0x7f96c value 72 Visualization of pointers int x = 5; int xPtr = x; / xPtr points to x / x xPtr variable name 0x7f96c 0x7f960 memory address 5 0x7f96c value 73 Visualization of pointers int x = 5; int xPtr = x; / xPtr points to x / int y = xPtr; / y’s value is / x xPtr y variable name 0x7f96c 0x7f960 0x7f95c memory address 5 0x7f96c value 74 Visualization of pointers int x = 5; int xPtr = x; / xPtr points to x / int y = xPtr; / y’s value is / x xPtr y variable name 0x7f96c 0x7f960 0x7f95c memory address 5 0x7f96c value 75 Visualization of pointers int x = 5; int xPtr = x; / xPtr points to x / int y = xPtr; / y’s value is / x xPtr y variable name 0x7f96c 0x7f960 0x7f95c memory address 5 0x7f96c value 76 Visualization of pointers int x = 5; int xPtr = x; / xPtr points to x / int y = xPtr; / y’s value is / x xPtr y variable name 0x7f96c 0x7f960 0x7f95c memory address 5 0x7f96c value 77 Visualization of pointers int x = 5; int xPtr = x; / xPtr points to x / int y = xPtr; / y’s value is / x xPtr y variable name 0x7f96c 0x7f960 0x7f95c memory address 5 0x7f96c value 78 Visualization of pointers int x = 5; int xPtr = x; / xPtr points to x / int y = xPtr; / y’s value is / x xPtr y variable name 0x7f96c 0x7f960 0x7f95c memory address 5 0x7f96c value 79 Visualization of pointers int x = 5; int xPtr = x; / xPtr points to x / int y = xPtr; / y’s value is 5 / x xPtr y variable name 0x7f96c 0x7f960 0x7f95c memory address 5 0x7f96c 5 value 80 Visualization of pointers int x = 5; int xPtr = x; / xPtr points to x / int y = xPtr; / y’s value is 5 / x xPtr y variable name 0x7f96c 0x7f960 0x7f95c memory address 5 0x7f96c 5 value 81 Visualization of pointers int x = 5; int xPtr = x; / xPtr points to x / int y = xPtr; / y’s value is 5 / x xPtr y variable name 0x7f96c 0x7f960 0x7f95c memory address 5 0x7f96c 5 value 82 Visualization of pointers int x = 5; int xPtr = x; / xPtr points to x / int y = xPtr; / y’s value is 5 / x = 3; / y is still 5 / x xPtr y variable name 0x7f96c 0x7f960 0x7f95c memory address 3 0x7f96c 5 value 83 Visualization of pointers int x = 5; int xPtr = x; / xPtr points to x / int y = xPtr; / y’s value is 5 / x = 3; / y is still 5 / y = 2; / x is still 3 / x xPtr y variable name 0x7f96c 0x7f960 0x7f95c memory address 3 0x7f96c 2 value 84 Pointer Assignments • pointers can be assigned to one another using = int x = 5; int xPtr1 = x; / xPtr1 points to address of x / int xPtr2; / uninitialized / xPtr2 = xPtr1; / xPtr2 also points to address of x / (xPtr2)++; / x is 6 now / (xPtr1); / x is 5 again / 85 Outline • Separate Compilation • Structures • define • Pointers – Passing by Value vs. Passing by Reference – Pointers and Arrays and Functions and Structs • Makefiles • Testing • Homework 86 Passing Variables • when we pass variables like this: int x = 5; AddOne(x); what happens to x 87 Passing Variables • when we pass variables like this: int x = 5; AddOne(x); a copy of x is made, and the changes made in the function are made to the copy of x • the changes we make to x while inside the AddOne() function won’t be reflected in the “original” x variable 88 Passing Variables • using pointers allows us to passbyreference – so we’re passing a pointer, not making a copy • if we pass a variable like this: AddOne(x); what we are passing is the address where x is stored in memory, so the changes made in the function are made to the “original” x 89 Two Example Functions passbyvalue: void AddOneByVal (int x) / changes made to a copy / x++; passbyreference: void AddOneByRef (int x) / changes made to “original” / (x)++; 90 Two Example Functions int x = 5; x variable name 0x7fa80 memory address 5 value 91 Two Example Functions int x = 5; AddOneByVal(x); x x (copy) variable name 0x7fa80 0x7fa8c memory address 5 5 value 92 Two Example Functions int x = 5; AddOneByVal(x); void AddOneByVal (int x) x++; x x (copy) variable name 0x7fa80 0x7fa8c memory address 5 5 value 93 Two Example Functions int x = 5; AddOneByVal(x); void AddOneByVal (int x) x++; x x (copy) variable name 0x7fa80 0x7fa8c memory address 5 6 value 94 Two Example Functions int x = 5; AddOneByVal(x); void AddOneByVal (int x) x++; x variable name 0x7fa80 memory address 5 value 95 Two Example Functions int x = 5; AddOneByVal(x); / x = 5 still / x variable name 0x7fa80 memory address 5 value 96 Two Example Functions int x = 5; AddOneByVal(x); / x = 5 still / AddOneByRef(x); x variable name 0x7fa80 memory address 5 value 97 Two Example Functions int x = 5; AddOneByVal(x); / x = 5 still / AddOneByRef(x); void AddOneByRef (int x) (x)++; x variable name 0x7fa80 memory address 5 value 98 Two Example Functions int x = 5; AddOneByVal(x); / x = 5 still / AddOneByRef(x); void AddOneByRef (int x) (x)++; x variable name 0x7fa80 memory address 5 value 99 Two Example Functions int x = 5; AddOneByVal(x); / x = 5 still / AddOneByRef(x); void AddOneByRef (int x) (x)++; x variable name 0x7fa80 memory address 5 value 100 Two Example Functions int x = 5; AddOneByVal(x); / x = 5 still / AddOneByRef(x); void AddOneByRef (int x) (x)++; x variable name 0x7fa80 memory address 6 value 101 Two Example Functions int x = 5; AddOneByVal(x); / x = 5 still / AddOneByRef(x); void AddOneByRef (int x) (x)++; x variable name 0x7fa80 memory address 6 value 102 Two Example Functions int x = 5; AddOneByVal(x); / x = 5 still / AddOneByRef(x); / x = 6 now / x variable name 0x7fa80 memory address 6 value 103 Outline • Separate Compilation • Structures • define • Pointers – Passing by Value vs. Passing by Reference – Pointers and Arrays and Functions and Structs • Makefiles • Testing • Homework 104 Pointers and Arrays • arrays are pointers – they’re pointers to the beginning of the array • but they are also only pointers • which is why there’s – no bounds checking – no way provided to determine length 105 Pointers and Arrays and Functions • because arrays are pointers, they are always passed by reference to a function • this means: – the program does not make a copy of an array – any changes made to an array inside a function will remain after the function exits 106 Pointers and Arrays • passing one element of an array is still treated as passbyvalue classes0 is a single variable of type CISCLASS, not a pointer to the array intArrayi is a single variable of type int, not a pointer to the array 107 Cstyle Strings • reminder: C strings are arrays of characters – so functions always pass strings by reference • remember scanf scanf(“d”, x); / for int / scanf(“s”, str); / for string / − there is no “” because C strings are arrays, so scanf is already seeing an address 108 Cstyle Strings in Functions • using in functions: / function takes a char pointer / void ToUpper (char word); char str = “hello”; ToUpper (str); • this is also a valid function prototype: void ToUpper (char word); 109 Pointers and Struct Members • remember, to access a struct’s member: cisClass.classNum = 190; • when we are using a pointer to that struct, both of the following are valid expressions to access the member variables: (cisClassPtr).classNum = 191; cisClassPtrclassNum = 192; 110 Pointers and Struct Members • the operator is simply shorthand for using and . together – the asterisk dereferences the struct so we can access it values, i.e., its member variables – the member variables are stored directly in the struct (not as pointers), so we can access them via dot notation, without needing to dereference (cisClassPtr).classNum = 191; cisClassPtrclassNum = 192; 111 Coding Practice • download starter files from the class website – http://www.seas.upenn.edu/cis190/fall2014 • will use structs to get some practice with – pointers – arrays – passing by reference LIVECODING LIVECODING 112 Outline • Separate Compilation • Structures • define • Pointers – Passing by Value vs. Passing by Reference – Pointers and Arrays and Functions and Structs • Makefiles • Testing • Homework 113 Makefiles • use to automate tasks related to programming – compiling program – linking .o files – deleting files – running tests • using a Makefile helps – prevent human error – facilitate programmer laziness 114 Makefile Basics • must be called Makefile or makefile • contains a bunch of rules expressed as: target: dependency list action • invoke a rule by typing “make target” in the command line 115 Makefile Basics • must be called Makefile or makefile • contains a bunch of rules expressed as: target: dependency list action this must be a tab, or it won’t work • invoke a rule by typing “make target” – while in the folder containing the Makefile 116 Makefile Basics • comments are denoted by a pound at the beginning of the line • the very first rule in the file will be invoked if you type “make” in the command line • there’s a lot of automation you can add to Makefiles – look for more info online 117 Makefile Basics • example Makefile on page for Homework 2 – more info in the Makefile’s comments • Makefiles will be required for all future programming homeworks – the first rule in the Makefiles you submit must fully compile and link your program – graders will use this to compile your program 118 Outline • Separate Compilation • Structures • define • Pointers – Passing by Value vs. Passing by Reference – Pointers and Arrays and Functions and Structs • Makefiles • Testing • Homework 119 Testing • unit testing – literal tests to make sure code works as intended – e.g., TwoPlusTwoEqualFour(...) for an Addition() function • edge case testing (or corner case, etc.) – ensure that code performs correctly with all (or at least many) possible input values – e.g., prevent program from accepting invalid input 120 Simple Testing Example / get month from user in integer form / printf(“Please enter month: “); scanf(“d”, month); 121 Simple Testing Example / get month from user in integer form / printf(“Please enter month: “); scanf(“d”, month); while (month JANINT month DECINT) scanf(“d”, month); 122 Simple Testing Example / get month from user in integer form / printf(“Please enter month: “); scanf(“d”, month); while (month JANINT month DECINT) printf(“\nd is an invalid month”, month); printf(“please enter between d and d:”, JANINT, DECINT); scanf(“d”, month); 123 / print string up to number given by length (or full string, whichever is reached first) / void PrintToLength(char str, int length) int i; for (i = 0; i length; i++) printf(“c”, stri); 124 Common Edge Cases • Cstyle string – empty string – pointer to NULL – without the \0 terminator • Integer – zero – negative/positive – below/above the min/max 125 Outline • Separate Compilation • Structures • define • Pointers – Passing by Value vs. Passing by Reference – Pointers and Arrays and Functions and Structs • Makefiles • Testing • Homework 126 Homework 2 • Trains – most difficult part of the homework is formatting the printing of the train cars – make sure output is readable (see sample output) • hw2.c, trains.c, trains.h (and answers.txt) – don’t submit the Makefile or any other files – take credit for your code 127
sharer
Presentations
Free
Document Information
Category:
Presentations
User Name:
Dr.MasonHanks
User Type:
Teacher
Country:
Germany
Uploaded Date:
23-07-2017