CS16, 10W, UCSB—H11: (Addresses, Pointers, Arrays, Etter, Section 6.1) Total points: ? (printable PDF)
Available online at: http://www.cs.ucsb.edu/~pconrad/cs16/10W/homework/H11
Accepted: on paper, in Lecture (11am Thursday Feb 11th)
Late Policy: No email submission allowed—and don't "slip it under my door". If you need to make it up, you must do so during office hours, or make an appointment to see me, and you must request this appointment within 48 hours of when the assignment was originally due.
Personal Day/Sick Day policy: Everyone is permitted one "personal day/sick day" when you get to make up a missed homework assignment for free during office hours or via appointment. After that, you may not make up the homework assignment—you can only earn back the points through extra credit opportunities. (For more details, see the syllabus and the homework policy)
Name: (3 pts)___________________________ UMail address (4 pts) ______________@umail.ucsb.edu
Lab Section (3 pts) Circle one: 3pm 4pm 5pm unknown
This assignment is due IN Lecture on Thursday.
It may ONLY be turned in during Lecture on Thursday.
Do NOT turn it in early to your TA on Tuesday in lecture,
or late to your TA in Lab on Thursday
.
Name of your pair programming partner(s), if you work together:
Read Section 6.1and 6.2 in your Etter textbook—and review your lecture notes from Thursday Feb 4.
In addition, keep in mind that in the textbook, Etter uses %u as the format specifier for pointers, while in lecture I tend to use %p instead.
The difference is that %u prints the address value as an "unsigned integer", in base 10, while %p prints the address value in hexadecimal.
Then answer these questions:
a = 1; address of a = 1245052
b = 2; address of b = 1245048
My question to you is this: if you ran this program on CSIL, would the output be the same or different? If different, which parts would be the same, and which parts would be different? And most importantly, explain why.
(Hint: the answer I'm looking for can be found somewhere in the textbook on pages 284-285.)
a = -858993460; address of a = 1245052(Hint: again, the answer I'm looking for can be found somewhere in the textbook on pages 284-285.)
b = -858993460; address of b = 1245048
Please turn over for more problems
Continued from other side
int a=3, b=4, *ptr;
ptr = &a;
int a=5, b=6, *ptr=&a;
b = *ptr;
int a=7, b=8, c=9, *ptr=&b;
a = *ptr;
*ptr = c;
int a=10, b=11, c=12 *p1=&b, *p2;
p2 = &c; a = *p1; p1 = &a;
int a=13, b=14, *p1=&a, *p2=&b, *p3;
(*p1) = (*p2); p3 = p1;
int a=15, b=16, *p1=&a, *p2=&b, *p3;
p3 = p1;
p1 = p2;
p2 = p3;