C Pointers Flashcards
What is a pointer?
A data type that contains a memory address
What do we use pointers for?
To indirectly get to the values of variables
When we declare an array, is the index automatically declared?
No, declaring a variable doesn’t create a pointer to the variable.
I can manipulate the index value without changing:
the array value
I can change pointer values without affecting:
the memory data
What do the * and -> operators do?
They say “look in memory for” as the array name does with [] notation for arrays.
With pointers, how many values are we dealing with?
Two; the address stored by the pointer and the value at the address the pointer points.
What is the & operator used for?
To give us the memory address of a variable
What is * used for?
Used to tell it to look through the pointer to the underlying data
Where do we include *?
Right before the variable name in the declaration.
What does this do?
int *integer_pointer;
Declares a place to store an address and the thing that is at that address is an integer.
What must we assign a pointer?
A memory address
How do we get a variable’s memory address?
Precede it with &
How do we set a pointer value in C code?
int *integer_pointer;
int a;
integer_pointer= &a;
How do we read or change underlying data?
Precede the variable name with a *
Example: int *integer_pointer; int a; int b = 20; integer_pointer = &b; a = *integer_pointer; *integer_pointer = 10;