C++ concepts Flashcards
What does it mean for a class to be ‘friend’ of another class.
It can access the private members of the class.
What is a class?
A user defined type that encapsulates many important mechanism.
Guaranteed initialization Implicit type conversion control memory management Operator overloading Polymorphism etc
What are header Files?
Are used to provide special declarations and definitions.
“cstdlib” and “iostream” are some examples.
What is the return value of the expression ‘int(ch)’?
Return the integer value associated with a character value ‘ch’.
How are Octal(base 8) and hexadecimal (base 16) integers represented?
Decimal ->256
Octal -> 0400
Hexadecimal -> 0x100
What is enumeration type?
Is a user defined type that can hold any of a set of discrete values.
They behave much like an int.
Common use is to provide meaningful names to a set of related values.
enum Day {SUN, MON, TUE, WED, THU, FRI, SAT};
enum Mood {HAPPY = 3, SAD =1 , ANXIOUS = 4, SLEEP =2};
Day today = THU;
Mood myMood = SLEEPY;
What 2 operators are used to manipulate pointers?
& -> address of. returns the address
*pointer -> dereferencing. returns the objects value from it’s address
The following expression will create three pointers to int. TRUE or FALSE.
int* x, y, z;
FALSE.
will declare on pointer variable x, and two variable as plain ints.
Name of an array is equivalent to a pointer to the array’s initial element and vice versa.
TRUE or FALSE
TRUE
What are Structures useful for?
Store aggregation of elements.
Each member can be of different type, unlike arrays.
struct Passanger{ string name; MealType mealPref; bool isFreqFlyer; string freqFlyerNo; };
What is the name of the memory used in C++ to store dynamically created objects?
Heap Memory or Free Store.
What is the use of the ‘new’ operator.
Dynamically allocates the correct amount of storage for an object of a given type and return a pointer to this object.
What is a memory leak? How can it happen?
If we were to change the address value of p without first deleting the structure to which it points, there would be no way for us to access this object.
What is the use of the ‘typedef’ operator?
Allows us to provide a shorter and more meaningful synonyms for various types.
typedef char* BufferPrt;
BufferPrt p;
What is namespace?
Is a mechanism that allows a group of related names to be defined in one place.
Helps organize global objects into natural groups and minimize the problem of globals.
using std::string; //makes just std::string accesible
using namespace std; //makes all of the std accessible