C vs. C++ Note: We'll use gdb a lot today for examples I recommend you learn to use it, or some other debugger Beej's guide to gdb I tend to favor putting the source code in a different window vs. tui mode Returning an array: Suppose we have a function that makes an array We don't know how long the array will be when writing the function dilution_levels ? What normally happens with return? Let's draw a picture of the stack Remember the stack from...some class or other? Has Stan talked about this in 211? There are a lot of ways 211 can go The stack and dynamic sizes How to avoid the dynamic (or large) size problem: Store the memory address instead Store the actual thing "somewhere else" "somewhere else" usually means the heap An address book works for addresses of different sized buildings So if the stack is just a memory area, can we change it? Sure Remember: my_array[5] means "The item 5 items above the beginning of my_array" my_array[0] is the first item because it's 0 items above the beginning "above" means "the address is numerically higher" here Let's change something in our main function, from a function CS475 goes into way more depth here Returning a pointer to a local array Alright, heap options for our array: 1. STL vector (C++ only) 2. new/delete (C++ only) 3. malloc/free (How we do it in C) 4. Make the caller of the function handle the problem (Also common in C) Time for getoutput: I think we talked about fork/exec a while back Now we can use it for something productive! How long will the output be? We don't know! realloc I'll do this completely in C, and make sure it works in C++ too Active learning (quiz) I'll make up a question about memory addresses