Hey everyone (especially Narue!),
I've ventured over to the C++ board again. I've been reading my C++ book (Data Structures and Algorithms in C++) again and want to fully grasp the concept of pointers. In the back of each chapter, a couple of exercises are available and I'm attempting to do them.
For the very first question, it's simply asking to figure out which assignment would cause compilation errors but unfortunately I can't find the solutions in the back of the book or online. :(
Q: If i is an integer and p and q are pointers to integers, which of the following assignments cause a compilation error?
a. p = &i; No error as p is assigned the address of i
b. p = *&i; Error as p is assigned the contents at the address of i
c. p = &*i; Error as p is assigned the address of the value at i
d. i = *&*p; No error as i is assigned the contents of the address containing the contents of p
e. i = *&p; No error as i is assigned the contents at the address of p
f. i = &*p; Error as i is assigned the address of the contents at p
g. p = &*&i; No error as p is assigned the address of the contents held at the address of i
h. q = *&*p; Error as q is assigned the contents at the address holding the contents of p
i. q = **&p; Error as q is assigned the contents holding the contents at the address of p
j. q = *&p; Error as q is assigned the contents at the address of p
k. q = &*p; No error as q is assigned the address holding the contents of p
I realize I could just test this by writing some code, but when I tested this a year ago in a lab, I was able to compile with some of those that actually should have caused a compilation error (and thus earned less than 100% on the problem). More importantly, I want to know if I properly described the assignments that were taking place.