10 - Pointers and Dynamic Arrays Flashcards
What is a pointer?
A pointer is the memory address of a variable.
Explain the meaning of this: double *p
Declares p to be a pointer variable that can hold one pointer that points to a variable of type double.
How do you declare a pointer?
Type_Name *Variable_Name1, *Variable_Name2, … ;
Example:
double *pointer1, *pointer2;
A pointer is an address. T/F?
T!
An adress in an integer. T/F?
T!
A pointer is an integer. T/F?
F! A pointer is an address, an address in an integer, but a pointer in not an integer.
How do you store an address in a pointer?
int* p1;
v1 = 0;
p1 = &v1;
The pointer variable, p1, now points to the address of v1.
What is wrong with this?
int* p1, *p2;
It can lead to confusion. Both p1 and p2 are now pointer variables, but the correct way to write this would be:
int *p1, *p2;
But for me, placing the asterix on the type is the best way. That means this should be written as:
int* p1;
int* p2;
What is the dereferencing operator?
The * in front a a pointer variable. It produces the variable to which it points.
What is the “address of operator”?
The & operator.