Pointers Flashcards

1
Q

What is a pointer

A

A pointer is any variable that holds the address of another variable

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

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++;

A

1001
2002
3004

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

What is a void pointer

A

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.

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

What is the main limitation of void pointers

A

The data pointed by them cannot be DIRECTLY dereferenced.

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

What is a null pointer

A

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.

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

Give a syntax example of a null pointer.

A

int *p
*p = 0; // p has a null pointer value

OR
*p = NULL // p has a null pointer value

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

What is dynamic memory allocation

A

This refers to performing memory allocation manually by a programmer

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

Dynamic memory is allocated using what operator? Give its syntax

A

operator : new

syntax:
pointer = new type
pointer = new type[number of elements]

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