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));
free(b);
return 0;
}
Pointer review: what does the above code print?
The office hours are Sun/Tue/Thu 8-11 PM at Hillhouse 17 Rm 111.
Please note that for this week only I will hold Office Hours tomorrow on Wednesday 15th February from 5PM-8PM instead of Tuesday.
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.8The 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.)
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.
exhash2.c added mymalloc and myfree.