cd ~/cs44/weeklylabs mkdir w05 cd w05 pwd cp ~newhall/public/cs44/week05/* . ls
Some more information about
C strings, and other
C and C++ links
Auto car1, car2; if(car1 != car2) { ...Let's look at some example code and try it out.
Here is some more information about C++ operator overloading In general, don't use C++ style reference parameters in code you write. However, reference parameters are used in some of the library code that we will use in subsequent lab assignments.
Let's look at the example code in refparams.cpp and talk about the semantics and syntax of C++ Reference Parameters. Then try running it to see what is going on.
Some more information about
references see Chapt. 11
In general, you can treat any chunk of memory as storing any type of values by recasting the address to the appropriate type, and dereferencing values from it using the syntax of the re-casted type. Here is a simple example
struct foo { int x; int y; }; char byte_arr[100]; struct foo *next; int i =0; next = (struct foo *)(&byte_arr[i]); next->x = 16; next->y = 100; // compute next valid index into space for an array of foo // (also in general we need to be careful about alignment and // padding if storing an array of structs into an array of bytes) i = i + sizeof(struct foo); next = (struct foo *)(&byte_arr[i]); next->x = 200; next->y = 18; // get value out of buffer by mapping type on to buffer // (re-casting as a type) and then dereference field values int val = ((struct foo *)(&byte_arr[i]))->x; // or re-cast the bytes it as what-ever type I want int val2 = *((int *)(&byte_arr[i])); char val3 = *((char *)(&byte_arr[i]));In gdb you can use the same syntax to re-cast a chunk of memory as a type and then access field values of that type.
Let's try out an example.