Memory and Pointers Flashcards
What is a pointer?
A pointer is a variable that contains an
address in memory.
What is the size of a pointer in 64 bit architecture?
8 bytes
Do functions like strcpy, strcat, strstr allocate memory for you?
No, you need to use malloc to allocate memory before
How to print a pointer? In hexadecimal?
printf(“ptr=%ld\n”,(unsigned long)&buff[5])
printf(“ptr=0x%lx\n”,(unsigned long) &buff[5])
When you increment a pointer to an integer how many units does it increase?
4, bc an int is 4 bytes
Why is using pointers efficient in coding?
It doesn’t require indexing, indexing in arrays (int[i]) requires multiplication.
What are some advantages of Pointer based arrays?
● You don’t need to know in advance the size of the array (dynamic memory allocation)
● You can define an array with different row sizes
● A jagged array uses multiple small blocks instead of one large block of memory.
What is Polymorphism?
Being able to use the same function with arguments of different types.
What are pointers to functions useful for?
Polymorphism