Introduction to C++ II Flashcards

1
Q

What are streams in C?

A

A stream is a flow of data in or out of our program. Terminal/file input/output included.

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

How does C handle streams?

A

Using terminal functions. E.g. using file IO functions to read/write from the terminal

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

How does C++ deal with streams?

A

Carries the practise on from C but with a simplified syntax.

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

What does the iostream library handle?

A

Printing/reading input streams.

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

In C when we didn’t want to make copies of data what did we do instead to pass the data?

A

Used pointers to access and modify values (unsafe)

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

What is C++’s solution to passing pointers?

A

Pass-by-reference

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

What is pass-by-reference?

A

Allows you to forward a variable into a function without copying it or taking a pointer to it.

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

Why is pass-by-reference good?

A

Useful for passing objects with large resources without causing them to be duplicated or have their ownership transferred.

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

What are references in C++?

A

References are a way of making the compiler do some of the work would do with pointers in C.

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

What can references not be?

A

References cannot be NULL. References must always refer to a variable or object.

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

What is the performance benefit of pointers and references?

A

There is no real difference performance wise.

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

Why do we use references if there is no real performance benefit?

A

A reference offers a cleaner syntax.

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

What is function overloading?

A

Allows multiple functions with the same name but different parameters (polymorphism)

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

How does the compiler know which overload to use?

A

Functions should be distinct and non-ambiguous. They must have different parameters or characteristics.

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

Can we overload constructors and destructors?

A

We can only overload constructors. We cannot overload destructors.

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

What does the compiler’s default constructor do?

A

The compiler’s default constructor will initialise non member variables to their default value. (e.g. int to 0)

17
Q

What happens if you declare any other overload constructor instead of deafult?

A

The compile will not include its own default constructor.

18
Q

What is operator overloading?

A

Allows the customization of operators to be used with user-defined objects/types.

19
Q

What does i++ do?

A

Returns the current value of i then increments it.

20
Q

What does ++i do?

A

Increments i first and then returns the incremented value,

21
Q

What are access functions?

A

Functions used to modify or retrieve the value of private data members of a class (getters and setters)

22
Q

What are inspector functions?

A

Functions used to inspect or query that state of an object but not modify its state (getter methods)

23
Q

What are member functions?

A

Functions that operate on an object’s data members and can access the object’s state through the this pointer.

24
Q

What are static functions?

A

Functions that are not associated with any particular object instance.

25
Q

What are the two types of polymorphism in C++?

A
  • Compile-time polymorphism
  • Run-time polymorphism
26
Q

What are examples of compile-time polymorphism?

A
  • Function overloading
  • Operator overloading
27
Q

What is an example of run-time polymorphism?

A
  • virtual functions/classes
28
Q

Why is passing pointers in C bad?

A
  • We have to deference a pointer every time we need the data
  • We have to manage memory
29
Q

What is ad-hoc polymorphism?

A

Allows us to overload functions and operators in a compiler-verified manner.

30
Q

What is runtime polymorphisms?

A

(virtual functions/classes) The specific function implementation to be run is determined at runtime based on
the type of the object used

31
Q

What is parametric polymorphism?

A

Allows us to write templates in our code, working with generic types and classes.

32
Q

What is one difference between pointers and references?

A

References cannot store null values. Pointers can be null.