09 Flashcards

1
Q

What is the function prototype for realloc?

A

void* realloc(void*, int size);

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

What does realloc do?

A

Realloc changes the size of a buffer which was previously malloced.

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

Does realloc always move the data?

A

No. If the new size is smaller than the old, the data may just be truncated. Also, if there is enough memory and the size is bigger than the old size, then it may just extend the allocated space.

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

What does realloc return on failure?

A

NULL

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

What does realloc return on success?

A

A pointer to the newly reallocated block of data.

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

What is the function prototype for memcpy?

A

void* memcpy(void *dst, void *src, size_t n);

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

What does the function memcpy do?

A

It copies n bytes of data from a source pointer to a destination pointer.

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

What is the function prototype for memmove()

A

void* memmove(void *dst, void *src, size_t n);

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

What is the difference between memcpy and memmove?

A

Memmove is identical except it promises to work regardless of how the memory blocks overlap. memcpy might not work correctly in this case.

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

How does memcpy work with structs?

A

It doesn’t. Don’t do it.

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

How many bytes need to be malloced to store the following string:
“abcdefg”?

A

8.

Always remember to leave an extra byte for the null terminator ‘\0’.

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

Which of the following constants does not exist?

INT_MIN, INT_MAX, UINT_MAX, UINT_MIN

A

UINT_MIN.

There is no need for this as it will always be 0.

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

What values does rand() return values between?

A

0 and RAND_MAX.

RAND_MAX is always at least 32767.

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

What method is used to seed the random numbers?

A

srand()

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