Copy semantics

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/12

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

13 Terms

1

What does const mean in C?

It means the variable’s value cannot be changed through that reference.

2

Why use const in function parameters?

To guarantee that values won’t be modified, improving safety and clarity.

3

What does int * const p mean?

p is a constant pointer; the address cannot change.

4

What does const int *p mean?

p is a pointer to a constant value; the value cannot change.

5

What does const int * const p mean?

p is a constant pointer to a constant value; neither address nor value can change.

6

What is the spiral rule in C declaration reading?

Start at the variable name and interpret in this order: arrays → functions → pointers → const.

7

Interpret char * str[10] using the spiral rule.

str is an array of 10 pointers to char.

8

What does void func(const struct * const p) imply?

The struct pointer p and the struct it points to are both constant.

9

What is a shallow copy in C structs?

It copies only the pointer, not the data; both structs share the same memory.

10

What is the purpose of a deep copy constructor?

It allocates new memory and copies data from another struct to a new, uninitialized one.

11

What does intvector_copy_assign do?

It copies data into an already-initialized struct, resizing memory safely.

12

What should you consider before copying a struct?

Whether the struct owns heap memory, to avoid memory issues.

13

Why is defensive programming important in C?

It prepares your code for future changes and misuse, especially in shared APIs.