Pointers Flashcards
What is a pointer
A pointer is any variable that holds the address of another variable
Suppose we define three pointers:
char *mychar
short *myshort
long *mylong
and that we know that they point to memory locations 1000, 2000 and 3000 respectively. What is mychar++;
myshort++;
mylong++;
1001
2002
3004
What is a void pointer
Void pointer is a special type of pointer that is allowed to point to any data type; from an integer value or float to a string.
What is the main limitation of void pointers
The data pointed by them cannot be DIRECTLY dereferenced.
What is a null pointer
A null pointer is a regular pointer that is of any type which has a special value that indicates that it is not pointing to any valid reference or memory address.
Give a syntax example of a null pointer.
int *p
*p = 0; // p has a null pointer value
OR
*p = NULL // p has a null pointer value
What is dynamic memory allocation
This refers to performing memory allocation manually by a programmer
Dynamic memory is allocated using what operator? Give its syntax
operator : new
syntax:
pointer = new type
pointer = new type[number of elements]