Fill in the code in practice_final.cpp
You are allowed full access to your prior work, internet searches, and all course materials.
Download
practice_final.zip. A Makefile (with gdb debug support) is included for your convenience.
Use wget and unzip in your terminal window to accomplish downloading the files.
Run the make by simply typing make:
make
Run the unit tests. (To get full credit your code must pass the unit tests and instructor code inspection):
./test
Run the valgrind utility on your code to make sure you do not have any memory leaks:
valgrind ./test
Place your completed practice_final.cpp files in a directory named practice_final at the top level of your git repo. This is optional as this practice exam will not be graded
Arrays can be declared with an explicit size:
char buffer[MAXSIZE+1] ;
// hold a string of at most MAXSIZE characters + terminating NUL
('\0')
Arrays can be initialized, which also sets the array's size and
the initial contents:
char mesg[] = "Hello!" ; // a 7 element array - 6 characters
in Hello! + terminating NUL
An array name is a constant pointer to the first (0th)
array element; thus:
mesg
== &mesg[0] ; // address of the first character in the
message.
mesg[0] == *mesg ; // the 0th element of an array is the same
as dereferencing mesg as a pointer.
Pointer variables (of the appropriate type) can be point to an array declaration:
char *pmesg =
mesg ; // *pmesg == mesg[0] == *mesg == 'H'
Pointers can be indexed like arrays (rarely done but
useful at times):
ch = pmesg[4]
;
// ch == 'o'
Pointers can have integers added or subtracted to
generate new pointers:
char *pnew = NULL ;
pnew = pmesg + 4 ; // pnew points to the fourth character past pmesg (here, *pnew ==
'o')
Pointer difference gives the "distance" in underlying type
units between two pointers:
int dist = 0 ;
dist = pnew - pmesg ; // dist == 4
Pointer can combine both dereferencing and pointer increments and decrements in one statement:
pmesg = mesg ;
ch = *pmesg++ ; // ch == 'H' and pmesg == &mesg[1]
pnew = mesg + 4 ;
ch = *pnew-- ; // ch == 'o' and pnew == &mesg[3]
pnew = mesg ;
ch = *++pmesg ; // ch == 'e' and pmesg == &mesg[1]
pnew = mesg + 4 ;
ch = *--pnew ; // ch == 'l' and pnew == &mesg[3]