Notably this statement "Using a pointer we can directly access the value stored in the variable which it points to. To do this, we simply have to precede the pointer's identifier with an asterisk (*), which acts as dereference operator and that can be literally translated to "value pointed by"."
So... If I had
1 2 3 4 5 6 7
int find_file(const dir_t *dir, string file_name, FILETYPE file_type,
int user);
/* REQUIRES: *dir is a valid directory pointer
* EFFECTS: Searches for file with matching name and file_type, which
* is also accessible by user. If such a file exists, return the file
* location. Return -1 otherwise.
*/
If I was trying to implement it... would i have to put the deference operator in front of dir?
As in...
1 2 3
for(int i=0; i<*dir.num_files; i++)
{
if(*dir.files[i]... // and so on
This is what I would have to do in this case, correct?
I much prefer the -> too - the reason the -> operator was invented was because pointer access to members is used so much. It makes the code much easier to read as well.