slides-2

slides-2 - Data Structures - CSCI 102 Housekeeping...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Additional rule for exam regrades To be eligible for exam regrades , you must write your entire exam in ink 1 Data Structures - CSCI 102 Copyright © William C. Cheng Housekeeping (1/18/2011) Assignment and exam regrades Submit within 2 weeks of initial grade notification
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Pointers 2 Data Structures - CSCI 102 Copyright © William C. Cheng Pointers (Ch 13) Must remember to clean up after yourself Usage can be error prone Why worry? Mistakes don’t always show up right away Mistakes can have weird symptoms Memory bugs are hard to understand & fix (even for professionals)
Background image of page 2
Let’s see some code 3 Data Structures - CSCI 102 Copyright © William C. Cheng Coding Exampls Assigning and passing variables by value Assigning and passing variables by references Assigning and passing pointers Displaying the addresses of variables Debuggers gdb (see quick summary on next slide) ddd (on aludra and nunki)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
print field after every cmd: (gdb) display f.BlockType assignment: (gdb) set f.BlockType=0 print field: (gdb) print f.BlockType printf(): (gdb) printf "%02x\n",buf[0] single-step at same level: (gdb) next single-step into a function: (gdb) step continue: (gdb) cont clear breakpoint: (gdb) clear run program: (gdb) run compile program with: start debugging: gdb hw1 -g set breakpoint: (gdb) break foo.c:123 The debugger is your friend! Get to know it! quit: (gdb) quit stack trace: (gdb) where 4 Data Structures - CSCI 102 Copyright © William C. Cheng Notes on gdb
Background image of page 4
5 Data Structures - CSCI 102 Copyright © William C. Cheng variables.cpp /* * 1) Demonstrate static, stack, heap variables. * 2) Declare a static int. * 3) Write a function that returns the square of a number. * 4) In main(), use a stack variable, call square() and print * the number and its square. Call malloc() to create an * integer, call square() and print the number and its square. * 5) Use gdb to look at the addresses. */
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Data Structures - CSCI 102 Copyright © William C. Cheng variables.cpp #include <iostream> using namespace std; static int z=3; int Square(int x) { return x*x; } int main(int argc, char *argv[]) { int x = 17; cout << "Square(" << x << ") = " << Square(x) << endl;
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/17/2011 for the course CSI 102 taught by Professor Billcheng during the Spring '11 term at USC.

Page1 / 20

slides-2 - Data Structures - CSCI 102 Housekeeping...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online