Introduction to C++ II Flashcards
What are streams in C?
A stream is a flow of data in or out of our program. Terminal/file input/output included.
How does C handle streams?
Using terminal functions. E.g. using file IO functions to read/write from the terminal
How does C++ deal with streams?
Carries the practise on from C but with a simplified syntax.
What does the iostream library handle?
Printing/reading input streams.
In C when we didn’t want to make copies of data what did we do instead to pass the data?
Used pointers to access and modify values (unsafe)
What is C++’s solution to passing pointers?
Pass-by-reference
What is pass-by-reference?
Allows you to forward a variable into a function without copying it or taking a pointer to it.
Why is pass-by-reference good?
Useful for passing objects with large resources without causing them to be duplicated or have their ownership transferred.
What are references in C++?
References are a way of making the compiler do some of the work would do with pointers in C.
What can references not be?
References cannot be NULL. References must always refer to a variable or object.
What is the performance benefit of pointers and references?
There is no real difference performance wise.
Why do we use references if there is no real performance benefit?
A reference offers a cleaner syntax.
What is function overloading?
Allows multiple functions with the same name but different parameters (polymorphism)
How does the compiler know which overload to use?
Functions should be distinct and non-ambiguous. They must have different parameters or characteristics.
Can we overload constructors and destructors?
We can only overload constructors. We cannot overload destructors.