80 likes | 180 Views
ENEE150 Recitation 5. Quiz 2. Good luck!. Pointers. Pointer declaration Memory address Accessing pointer memory Array names are pointers Pointer arrays Case 1 i nt a, b, c; int *pa1[3] = {&a, &b, &c}; Case 2 int d[10], e[12], f[5]; i nt *pa2[3] = {d, e, f} What is pa2?.
E N D
Quiz 2 • Good luck!
Pointers • Pointer declaration • Memory address • Accessing pointer memory • Array names are pointers • Pointer arrays • Case 1 • int a, b, c; • int *pa1[3] = {&a, &b, &c}; • Case 2 • int d[10], e[12], f[5]; • int *pa2[3] = {d, e, f} • What is pa2?
Incrementing and decrementing pointers changes the memory address by the size of the variable type (ie. char, int, float) • Array names are pointers • caution.c • ptr_arith.c
Homework 2 • Problem 1 – Test vectors • Test 7 functions in required_functions.o • Think of .o file as .c file except you can’t read the code • Can include checkers.h since you need definitions, etc. • Initialize board • Print board (may have to do this more than once) • Run functions • Look at output file to see what tests need to be made for each function • gcc test1-driver.c required_functions.o
Homework 2 • Problem 2 – Script • Use a for loop…it makes things easier • foreachi (1 2 3 4) • $i • end • a.out > outputfile • Changes stdout to the output file instead of the screen • diff <file1> <file2> • Shows the difference between the files • echo “hello” • Prints out “hello” to the screen
Exercise 1 • Try creating an array of 5 integers and then incrementing each element
Exercise 2 • Try inputting an integer pointer from main into a function, change the contents of the integer (that the pointer is pointing to) within that function, and then print out the integer value in main