CSC161 2010F Imperative Problem Solving
[Skip to Body]
Primary:
[Front Door]
[Schedule]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
-
[Assignment]
[Lab]
Groupings:
[EBoards]
[Assignments]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
Related Courses:
[CSC195 2003S (Rebelsky)]
[CSC161 2009F (Coahran)]
[CSC161 2010S (Walker)]
Misc:
[SamR]
[ISO]
[GNU Coding Standards]
Summary: We continue to explore pointers, particularly the relationship between pointers and arrays.
Prerequisites: Familiarity with pointers.
Finish the lab on pointers.
In exercise 3 of the lab on pointers, you added code to declare two arrays.
a. Add code to determine the address of element 0 of each of those arrays.
b. Add code to determine the address of element 1 of each of those arrays.
c. Add code to determine the address of element 2 of each of those arrays.
d. What do these results suggest about the organization of the arrays?
e. Add the following line to your program.
printf ("%s: %p (%u)\n", "anthill", (void *) a, (unsigned int) a);
f. What do you expect this to print out (relative to what you printed for element 0)?
g. Check your answer experimentally.
a. Add the following lines to your main
method after the
declaration of anthill
.
int *wombat = anthill;
b. What value do you expect to get when you print out wombat
?
(Express this relative to the value of anthill[0]
.)
c. Check your answer experimentally.
d. What value do you expect to get when you print out wombat + 1
?
(Express this relative to the value of anthill[0]
.)
e. Check your answer experimentally.
f. What does this suggest about adding to pointers?
a. Add the following code to initialize anthill
.
int i; for (i = 0; i < 9; i++) anthill[i] = i; anthill[9] = -1;
b. What do you expect the following code to do?
int *wombat = anthill; while (*wombat >= 0) { printf ("%d\n", *wombat); wombat++; }
c. Check your answer experimentally.
[Skip to Body]
Primary:
[Front Door]
[Schedule]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
-
[Assignment]
[Lab]
Groupings:
[EBoards]
[Assignments]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
Related Courses:
[CSC195 2003S (Rebelsky)]
[CSC161 2009F (Coahran)]
[CSC161 2010S (Walker)]
Misc:
[SamR]
[ISO]
[GNU Coding Standards]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Wed Oct 27 09:41:47 2010.
The source to the document was last modified on Wed Oct 27 09:41:45 2010.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CSC161/2010F/Labs/pointers-revisited-lab.html
.
A PDF version of this document may be found at
http://www.cs.grinnell.edu/~rebelsky/Courses/CSC161/2010F/Labs/pointers-revisited-lab