C++ Language Flashcards
What can you tell us about it: a conditional operator?
Its a notion for some kind of if else
Conditional expression: If else
Difference between conditional statement and a condition expression
With a condition expression you are choosing one of two expression based on a boolean outcome
Condition statement: you are selecting one of two statements based on a boolean outcome.
All languages have condition statements not all languages have condition expressions
Abstract classes in C++
A class that doesn’t contain member functions, but only contains prototypes
Difference between a java abstract class and interface
If it was an interface you cant have variables In an abstract class you can have variable constants and prototypes In an abstract class you can have functions that are clearly defined
Major difference between java and c++?
The way they treat multiple inheritance
What is the difference between private and protected class members:
Private: are only accessible within the class defining them Protected: are accessible in the class that defines them and in classes that inherit from that class.
What is “this.” Give an example of when you would use “this.”
"This" refers to the current object. Example: public MyThisTest(int a){ this.a = a; // Assigns the value of the parameter a to the field of the same name }
What are the initialization and the assignment phases of a constructor? What is each used for?
The initialization phase, data members of class type are always initialized explicitly in the constructor initializer list. Initalization happens before any the statement execution of the constructor body. Assignment phase is when one object is assigned the value of another object. This happens in the constructor body.
Having a pointer as a class data member can lead to some undesirable side effects. What should you add to a class to avoid these side effects?
You can add a delete destructor (which guarantees the reset of the pointer) or add an implementation of the free() function
void you(long a, longb) {cout<< "long";} void you(double a, doubleb){cout<;} int main a. b; you(a,b); }
overloading function “you” while using same signature (is ambiguous). Code in 5a does not compile and thus does not run
int main(){ const char* what = "Is This"; what = "interesting"; cout<<< *what; }
Declaration of character array as a constant and cannot be changed does not compile and does not run
int& Now(){ int Where = 1; Where = Now(); cout << Where; }
Sends a warning that reference to local variable where is returned but it complies and runs with an output of 1
class Where{ public: int here; int foo() const; int bar() const; };
int Where :: foo() const{ here = here + 5; return here; } int Where ::bar() const{ return here + 5; } int OhNo(const Where* Now){ return now->bar(); } int main(){ Where* IsIt = new Where; cout
/* foo() and bar() are set as constant numbers and are thus read-only and you cannot manipulate any of the data members inside of it(the function(s)). Also, int here was never initialized. Any references to here are null pointer exceptions.
a. class Top{ public: int a; Top(int x) {a=x;} }; class Bottom : public Top{ public: int b; Bottom() : Top(5) {b = 0; a = 0;} }; int main(){ Bottom barrel; cout
/* compiles and runs with output of 0 0 */
class Top{ public: void Hat(char *string){cout Hat(5.5) Rung->Hat(“cat”);}
//overloading function you while using same signature (is ambiguous). Code in 7b does not compile and thus does not run */