CS 223 - Spring 2017. 2/15

Welcome to CS 223!

Logical problem of the day

int main(int argc, char ** argv) {
  int a[3] = {1,3,5};
  printf("%d\n", *a+1); 
  printf("%d\n", *(a+1)); 
  int * b = malloc(sizeof(int)*3);
  *b = 1;
  *(b + 1) = 3;
  *(b + 2) = 5;
  printf("%d\n", *b+1); 
  printf("%d\n", *(b+1)); 
  return 0;
Pointer review: what does the above code print?

Lecture 10: Introduction to C: valgrind, hash tables, midterm review


  • Office hours:
    The office hours are Sun/Tue/Thu 8-11 PM at Hillhouse 17 Rm 111.
  • My office hours this week are Wednesday 3-5pm. (today)

  • From Bilal Abu-Ghazaleh on piazza:

    Please note that for this week only I will hold Office Hours tomorrow on Wednesday 15th February from 5PM-8PM instead of Tuesday.

  • Midterm exam Wednesday February 22nd in class. topics

    Assignment 2 grades

    hw2 grade reports have been emailed. If you handed in hw2 and did NOT get an email, let me know.

    Here are the statistics:

    Grade			        Hours
    Max	40			30.8
    Min	0			0.0
    Avg	28.1			9.5
    Median	31			10.0
    Stdev	10.5			6.8
    The tests are available at /c/cs223/hw2/Tests

    You may resubmit for 50% incremental credit up to Sunday night at midnight. If you got 0 points because of compilation issues, you can recover full credit. (I do not want to encourage compilation errors.)

  • Grading issues - emailed report different from self test on zoo:
    I just looked into this specific case -- it's because he has the
    following line in his code:
          bool trace, nexttrace, firsttrace, besttrace, ffdtrace, bfdtrace = false;
    which of course only actually sets bfdtrace to false and leaves the
    other values uninitialized, leading to non-deterministic behavior.  I
    ran the test script on his code a few times and got 34/40 most of the
    time, so I'm happy to change his grade to 34/40 -- what do you think?
    I've noticed a lot of bugs at office hours recently stemming from not
    initializing memory properly -- I think introducing students to
    valgrind would really help.

    Assignment 3

    Problem set 3
  • Piazza note about pointers

  • Note: when you expand the hash table, you need to insert the existing items into the new hash table. The buckets numbers will likely change.

    Lecture Starts Here

    valgrind redux

    A week or two ago, I introduced a way to track the pointer life cycle, comprising birth (malloc, calloc), growth (realloc), and death (free). valgrind solves part of the problem. the my functions provide additional useful information.


    exhash2.c added mymalloc and myfree.

    Hash Tables

    Aspnes: Hash Tables

  • hw3/hash.h from hw3
  • hw3/hashtest.c uses hash.h, string keys, linked lists
  • hw3/bighashtest.c uses hash.h, string keys, linked lists

  • Hash Functions:
  • exhash.c integer keys, linear probing
  • exhash2.c string keys, linear probing
  • examplehash.c integer keys, linear probing, dummy item for deletes
  • examplehash2.c string keys, linear probing, dummy item for deletes