C++ concepts Flashcards

1
Q

What does it mean for a class to be ‘friend’ of another class.

A

It can access the private members of the class.

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

What is a class?

A

A user defined type that encapsulates many important mechanism.

Guaranteed initialization
Implicit type conversion
control memory management
Operator overloading
Polymorphism
etc
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are header Files?

A

Are used to provide special declarations and definitions.

“cstdlib” and “iostream” are some examples.

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

What is the return value of the expression ‘int(ch)’?

A

Return the integer value associated with a character value ‘ch’.

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

How are Octal(base 8) and hexadecimal (base 16) integers represented?

A

Decimal ->256
Octal -> 0400
Hexadecimal -> 0x100

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

What is enumeration type?

A

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;

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

What 2 operators are used to manipulate pointers?

A

& -> address of. returns the address

*pointer -> dereferencing. returns the objects value from it’s address

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

The following expression will create three pointers to int. TRUE or FALSE.

int* x, y, z;

A

FALSE.

will declare on pointer variable x, and two variable as plain ints.

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

Name of an array is equivalent to a pointer to the array’s initial element and vice versa.

TRUE or FALSE

A

TRUE

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

What are Structures useful for?

A

Store aggregation of elements.

Each member can be of different type, unlike arrays.

struct Passanger{
string name;
MealType mealPref;
bool isFreqFlyer;
string freqFlyerNo;
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the name of the memory used in C++ to store dynamically created objects?

A

Heap Memory or Free Store.

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

What is the use of the ‘new’ operator.

A

Dynamically allocates the correct amount of storage for an object of a given type and return a pointer to this object.

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

What is a memory leak? How can it happen?

A

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.

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

What is the use of the ‘typedef’ operator?

A

Allows us to provide a shorter and more meaningful synonyms for various types.

typedef char* BufferPrt;

BufferPrt p;

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

What is namespace?

A

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

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

When arguments are passed by value, the system makes a copy of the variable to be passed to the function.

TRUE or FALSE

A

TRUE

17
Q

What is more efficient way of passing arguments to a function, other than by value?

A

Passing by reference.

The best is to pass a constant reference.
Which tells the compiler to that the function cannot change the value. And the function is now allowed to pass the argument to another function that modifies its value

void someFunc(const Passanger& pass){
pass.name = "new Name"}; Illegal.
18
Q

Would Passing an array by value results in making a copy of the entire array?
YES or NO?

A

NO.

When an array is passed to a function, it is converted to a pointer to its initial element.

19
Q

What are the two class member functions?

A

Accessor function, which read data from the class. Often identified by a ‘const’ keyword in declaration

Update Function, which may alter the class data.

class Passanger{
public:
Passanger();
bool isFreqFlyer() const;
}
20
Q

What are the three types of constructors of a class?

A

Default -> used in the absence of initialization info.

given Values

copy -> given an object, copy its data into the new one.