I'm learning C at the moment and wrapping my head around pointers. I understand &
can be used to retrieve the address of a var in memory. I'm curious to know why this particular call to read() is passing the address of the char var.
Of course, the intention here is to read the input from shell 1 by 1, but why is it necessary to provide the address of c
? Or is it merely a preference? I guess I'm not clear on when using a pointer is necessary.
int main() {
char c;
while (read(STDIN_FILENO, &c, 1) == 1 && c != 'q');
return 0;
}