Lab 8: Pointer Arithmetic - PowerPoint PPT Presentation

1 / 3
About This Presentation
Title:

Lab 8: Pointer Arithmetic

Description:

Use the Debugger to step through your code: Put a breakpoint on the line with the first 'cout' ... step through your program using the debugger before leaving ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 4
Provided by: jimand
Category:

less

Transcript and Presenter's Notes

Title: Lab 8: Pointer Arithmetic


1
Lab 8 Pointer Arithmetic
  • Test your machine first by writing the Hello,
    World program
  • Write the strcpy() function using pointer
    arithmetic (no array index)
  • The main function is provided on the back of this
    sheet
  • Use the Debugger to step through your code
  • Put a breakpoint on the line with the first
    cout
  • Step into the strcpy() function
  • Create watches for local pointer variables
  • Step through strcpy() and watch the copy
    operation
  • Do your own work (Dont copy other peoples code)
  • Demonstrate that your program is working AND that
    you know how to step through your program using
    the debugger before leaving

Sample Console Output
Before Now is the Time, For all good After For
all good, For all good Press any key to continue
2
Code (1)
  • include ltiostream.hgt
  • void strcpy(char str1, char str2)
  • void main()
  • char str120 "Now is the Time"
  • char str220 "For all good"
  • cout ltlt "Before " ltlt str1 ltlt ", " ltlt str2 ltlt
    endl
  • strcpy(str1,str2)
  • cout ltlt "After " ltlt str1 ltlt ", " ltlt str2 ltlt
    endl

3
Code (2)
  • void strcpy(char str1, char str2)
  • char ptr1 str1
  • char ptr2 str2
  • while (ptr2 ! '\0')
  • ptr1 ptr2
  • ptr1
  • ptr2
  • ptr1 '\0'
Write a Comment
User Comments (0)
About PowerShow.com