Thus, the following declaration statement creates a variable named student and of type char *.
char *student;
In the student variable, we can store the address of an object consisting of a sequence of (contiguous) characters; therefore, if we know the length of the sequence we can access the individual characters.
Like this:
* (student + index)
Or like this:
student [index]
Where index is an integer variable ranging in value from 0 to the length of the sequence minus one.
[Accelerate your learning and become a competent programmer: pretty-function.org]
OK, thanks ibex - but just to make sure I get it, are we defining the student variable as a char because it is going to be a memory address, or because we want to store information like a string, “Francis Smith”?
We are defining the student variable as a char * because we want to assign to it the address of a character string (a character string is a sequence of characters stored in memory.)
const char * student = "Francis Smith" ;
student = "Foo Bar" ; // Now points to "Foo Bar"
// Make a string of 63 repeated '*'
char * bar = (char *)malloc (64 * sizeof (char));
memset (bar, '*', 63);
bar [63] = 0;
// Print
printf ("%lu: %s\n", strlen (bar), bar);
// This prints 63: ***************************************************************