🔬 Lab
CS 240 Lab 6/7
Learning Goals & Reflection
CS 240 Lab 6/7
Learning Goals
Core Goals
Students can:
- Explain pointers and addresses:
(
)
- Explain how a pointer references other data.
- Explain what a pointer actually consist of in terms of bits.
- Explain what the unary
*
operator does in C, using the word ‘dereference.’ - Explain what the unary
*
type modifier means in C. - Explain what the unary
&
operator does in C. - Explain which part of the HW Arch model CPU pointers would be stored in, and which part of the CPU the data they point to would be stored in.
- Use
gdb
to debug C code: ( )- Run a program via
gdb
, set a breakpoint, and step through code. - Use
gdb
commands to inspect the values of variables and show the stack of active function calls. 1 Usevalgrind
to check C code for memory errors: - Run a program with
valgrind
and observe the resulting report. - Identify which parts of your code to investigate based on
valdgrid
reports.
- Run a program via
- Read and write C code using pointers:
(
)
- Identify which variables are pointers in C code, and the types of data they point to.
- Identify the types resulting from expressions involving the
*
and/or&
operators, and whether or not they match the types of variables they are assigned to. - Identify pointer dereferences which point to uninitialized data and therefore lead to undefined behavior.
- Declare array, string, and pointer variables, using static initial data.
- Use
printf
to print the value of a pointer as well as the value of the data it points to. - Write a
while
orfor
loop that uses pointer arithmetic to iterate through an array or string.
- Explain how arrays and strings are implemented in C:
(
)
- Identify which element of an array or character of a string is being accessed by code that uses pointer arithmetic.
- Explain why an array in C must always be accompanied by extra information, and what that information is.
- Explain why strings do not need this extra information.
Stretch goals
- Explain pointers and addresses:
(
)
- Explain what happens when the
&
operator is applied to a variable which is storing a pointer.
- Explain what happens when the
- Read and write C code using pointers:
(
)
- Give an example of code that will cause a segmentation fault.
- Explain what
malloc
does at a high level: ( )- Explain what argument
malloc
takes and what result it returns. - Explain what
free
is used for.
- Explain what argument
Extra goals
- Explain what
malloc
does at a high level: ( )- Explain why we always cast the result from
malloc
.
- Explain why we always cast the result from
Reflection
Note: Make sure to use the ‘print’ dialog to save this page as a PDF when you’re done.
I’m most confident in (list a few):
I’m least confident in (list a few):
Questions (please take the time to ask at least one, thinking of a question will help you cement what you’ve learned):