1 / 17

Recitation February 20, 2014

Recitation February 20, 2014. Homework 1 grades: available online Homework 2: due Feb. 26th Office hours: 9-11, Thursdays By appointment. Announcements. Quiz!. gcc –g filename.c Useful commands “break”: inserts a breakpoint b reak filename.c : 34 break func_name

thanh
Download Presentation

Recitation February 20, 2014

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Recitation February 20, 2014

  2. Homework 1 grades: available online • Homework 2: due Feb. 26th • Office hours: • 9-11, Thursdays • By appointment Announcements

  3. Quiz!

  4. gcc –g filename.c • Useful commands • “break”: inserts a breakpoint • break filename.c: 34 • break func_name • “continue”, “step”, “next”: control progress through the program after a breakpoint • “where”, “up”, “down”:provides information about location of stopping point • “watch”, “disp”: used to track variable values • watch var_one (sets a “watchpoint” on var_one” • dispvar_one (shows the value and type of var_one” GDB basics

  5. http://web.cecs.pdx.edu/~jrb/cs201/lectures/handouts/gdbcomm.txt (command examples) • http://www.stanford.edu/class/cs107/other/gdbrefcard.pdf (cheat sheet!) • http://www.yolinux.com/TUTORIALS/GDB-Commands.html • Links courtesy of Becky Gagnon Useful GDB resources

  6. Fantastic tools for testing! • Things to remember: • #!/bin/csh goes at the top • To be able to run the script, type “chmod 700” Scripts

  7. Decimal to binary: • 15610 to 100111002 • 156/2= 78 R 0 • 78/2=39 R 0 • 39/2=19 R 1 • 19/2=9 R 1 • 9/2=4 R 1 • 4/2=2 R 0 • 2/2=1 R 0 • 1/2= 0 R 1 Binary Conversions

  8. 1B16 to 110112 • Convert 1B16 to a decimal value: • 16*101+11*100=2710 • Convert 2710 to 110112 • 27/2= 13 R 1 • 13/2= 6 R 1 • 6/2= 3 R 0 • 3/2=1 R 1 • 1/2=0 R 1 • For Hex, you can go straight to decimal! • 1B: 1=0001, B=1011 : 00011011 Binary Conversions

  9. Easy conversion from binary to octal and hex: • 11010101102: • 001101010110 1 5 2 6 15268 • 001101010110 3 5 6 35616 • For binary to hex, group the binary in groups of four from right to left. • For binary to octal, group the binary in groups of three from right to left. Binary Conversions

  10. Pointers can be declared on the same line as other variables of the same variable type: • intnum_var=1, *num_pointer; • char letter=‘T’, *letter_pointer; • num_pointer=&num_var; • letter_pointer=&letter; • What about a pointer to a pointer? Pointer initialization

  11. Use “ * “ before the pointer name to access its value. • Question: Are pointers a two way street? int Jay=63, int *tonight_show_host, *Jimmy; tonight_show_host=&Jay; printf(“The age of the last Tonight Show host is %i”, *tonight_show_host); Jimmy=tonight_show_host; *tonight_show_host=39; printf(“Jimmy Fallon’s age is %i, Jay Leno’s is %i, The Tonight Show host’s age is %i. \n”, *Jimmy, Jay, *tonight_show_host); Dereferencing Pointers

  12. By the end of the code, • Jimmy=39 • tonight_show_host=39 • Jay=39 • That’s something important to consider when you modify pointers!! If you modify the value the pointer is pointing to, you also modify the variable that the pointer points to!! Dereferencing Pointers

  13. So what about that pointer to a pointer? int number, *point, **still_pointing; number=900; point=&number; still_pointing=&point; • What does **still_pointing equal? &still_pointing? *still_pointing? More Pointers

  14. **still_pointing=900 • *still_pointing= address of “point” • still_pointing= address of “still_pointing” • How would this be useful? More Pointers

More Related