CS220 Week 4 Homework Due Feb. 26, 2016 Name: 1. Given the following C code: int x = 1000000001; float fx=x; if (x==fx) printf("x and fx are the same"); else printf("x and fx are different"); ... what will get printed? Why? 2. Given the following C code: int func(char a[],char b[]) { while((*a)) if (*a++)!=(*b++)) return 0; if ((*b)) return 0; return 1; } a) What will func("string 1","string 1") return? b) What will func("string 1","string") return? c) What does func do? 3. Are the following statements true or false... a) ___ If the only command I type in a gdb session is "run", then my program will run to completion. b) ___ In gdb, if I type "n", and hit enter twice, I will execute exactly two C statements c) ___ In gdb, if I type "b 21 if (i>20)", then gdb will stop the next time I execute line 21 d) ___ In gdb, if I type "p myfn(x*3)", where x is a variable and myfn is a function in my code, then gdb will print out the return value of myfn. e) ___ It is possible in gdb to set a breakpoint at line 54 of my code, and print out the value of a variable every time that breakpoint is reached. 4. Given the following C code (where %p in printf means print the hexadecimal value of a pointer): int vec[4]={6,7,8,9}; int * vecptr=vec; printf("Vector is at %p\n",vecptr); printf("vec[2] is at %p\n",vecptr+2); printf("vec[2] is not at %p\n", (char *)vecptr+2); If the first printf statement results in "Vector is at 0x5fcb00", a) What will the second printf statement print? b) What will the third printf statement print? 5. Given the following C code: int matrix[2][3]; int *mptr=&matrix[0][0]; int row; int col; for(row=0; row<2; row++) { for(col=0; col<3; col++) { matrix[row][col]=(row*10) + col; } } printf("The fifth element of matrix is %d\n",*(mptr+5)); What will the printf statement print?