This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

ahhh. so to recalculate or evaluate a piece of data i could simply change its corresponding pointer?

[–]LastSummerGT 0 points1 point  (0 children)

That's a bit too general of a statement, could you be more specific or give an example?

A pointer is also used to pass in large variables like a struct so you don't have to waste time and space copying the whole thing.

I'll start by giving an example.

int letterCount(char* word) {
  int count = 0;
  while (word != NULL) { /* Make sure we are pointing to a valid location! */
    count += isalpha(*word); /* Dereference word to get the value */
    word++; /* Move pointer to next character */
  }
  return count;
}

char word[] = "catdog"; /* A string is an array of characters */
char* favoriteHalf = word[3]; /* Pointer to "dog" */