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.
What does the compiler’s default constructor do?
The compiler’s default constructor will initialise non member variables to their default value. (e.g. int to 0)
What happens if you declare any other overload constructor instead of deafult?
The compile will not include its own default constructor.
What is operator overloading?
Allows the customization of operators to be used with user-defined objects/types.
What does i++ do?
Returns the current value of i then increments it.
What does ++i do?
Increments i first and then returns the incremented value,
What are access functions?
Functions used to modify or retrieve the value of private data members of a class (getters and setters)
What are inspector functions?
Functions used to inspect or query that state of an object but not modify its state (getter methods)
What are member functions?
Functions that operate on an object’s data members and can access the object’s state through the this pointer.
What are static functions?
Functions that are not associated with any particular object instance.