Memory and Pointers Flashcards

1
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

What is a pointer?

A

A pointer is a variable that contains an
address in memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the size of a pointer in 64 bit architecture?

A

8 bytes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Do functions like strcpy, strcat, strstr allocate memory for you?

A

No, you need to use malloc to allocate memory before

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to print a pointer? In hexadecimal?

A

printf(“ptr=%ld\n”,(unsigned long)&buff[5])

printf(“ptr=0x%lx\n”,(unsigned long) &buff[5])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When you increment a pointer to an integer how many units does it increase?

A

4, bc an int is 4 bytes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why is using pointers efficient in coding?

A

It doesn’t require indexing, indexing in arrays (int[i]) requires multiplication.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are some advantages of Pointer based arrays?

A

● 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Polymorphism?

A

Being able to use the same function with arguments of different types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are pointers to functions useful for?

A

Polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly