C++Deck Flashcards

1
Q

<p>What are the 3 different categories of data types present in C++?</p>

A

<p>Fundamental data types, User defined data types, Derived data types</p>

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

<p>Name the C++ fundamental data types</p>

A

<p>1. Boolean type (bool)<br></br>2. Character types (char, wchar_t)<br></br>3. Integer types (int, long long ...)<br></br>4. Floating-point types (double, long double ....)<br></br>5. Void</p>

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

<p>What is the void type?</p>

A

<p>1. Type with an empty set of values (no value applies to it).<br></br>2.Incomplete type that cannot be completed.</p>

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

<p>What is an incomplete type?</p>

A

<p>A type that is not defined or void type.</p>

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

<p>What is nullptr_t?</p>

A

<p>Answer:<br></br>1. nullptr_t solves previous ambiguity problems with NULL<br></br>2.nullptr_t is the type of the nullptr literal.<br></br>3.It is a distinct type that it's not itself a pointer type.<br></br><br></br>Read more: <br></br>https://dzone.com/articles/what-exactly-nullptr-is-in-c</p>

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

<p>What RAII abbreviation means?</p>

A

<p>Resource Acquisition In Initialization</p>

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

<p>What is RAII Intent?</p>

A

<p>Answers:<br></br>1. To guarantee the release of a resource at the end of scope.<br></br>2.To guarantee no memory leaks<br></br><br></br>Read more: <br></br>http://www.vishalchovatiya.com/7-advance-cpp-concepts-idiom-examples-you-should-know/#Return-Type-Resolver</p>

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

<p>What is example RAII Implementation?</p>

A

<p>Answer:<br></br>1.Wrap resource into a class<br></br>2.Resource acquired in the constructor immediately after it's allocation<br></br>3.Destructor automatically releases resource<br></br>4.Resource used via interface<br></br><br></br>Read more: <br></br>http://www.vishalchovatiya.com/7-advance-cpp-concepts-idiom-examples-you-should-know/#Return-Type-Resolver</p>

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

<p>Why RAII is imporant?</p>

A

<p>Answer:<br></br>1. To not forget to release resource.<br></br>2. If a function returns early (throws, returns, etc...) resource may be leaked.<br></br><br></br>Read more:<br></br>http://www.vishalchovatiya.com/7-advance-cpp-concepts-idiom-examples-you-should-know/#Return-Type-Resolver</p>

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

<p>What are RAII usecases?</p>

A

<p>Answer:<br></br>In acquisition/release of resource with:<br></br>1)new/delete (memory)<br></br>2)lock/unlock (mutex)<br></br>3)open/close (file)<br></br>4)and others<br></br><br></br>Read more:<br></br>http://www.vishalchovatiya.com/7-advance-cpp-concepts-idiom-examples-you-should-know/#Return-Type-Resolver</p>

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

<p>What is the intent of return type resolver idiom?</p>

A

<p>Answer:<br></br>To deduce the type of the object being initialized or assigned to.<br></br><br></br>Read more:<br></br>http://www.vishalchovatiya.com/7-advance-cpp-concepts-idiom-examples-you-should-know/#Return-Type-Resolver</p>

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

<p>What is NULL?</p>

A

<p>NULL is a MACRO that is evaluated to integer with value 0</p>

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

<p>What is the intent of Type Erasure?</p>

A

<p>Answer:<br></br>To create generic container that can handle variety of concrete types.</p>

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

<p>What we refer to when we say the implementation's data model?</p>

A

<p>The sizes of the fundamental data types that are made by each implementation is referred to as the data model.</p>

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

<p>What are the four data models that found wide acceptance?</p>

A

<p>int/long/pointer notation (size in bytes)<br></br><br></br>32 bit systems:<br></br>LP32 (2/4/4 Win16) or ILP32 (4/4/4 Win32, Unix)<br></br>64 bit systems<br></br>LP64 (4/4/8 Win64) or ILP64 (4/8/8 Unix)</p>

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

<p>What are the integer types modifiers?</p>

A

<p>Signedness: signed (default) and unsigned.<br></br>Size: short (at least 16 bits) and long (at least 32 bits) and long long (C++11 at least 64 bits).</p>

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

<p>When integer types overflow is undefined?</p>

A

<p>When you overflow a signed integer.</p>

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

<p>At least how many bits is short?</p>

A

<p>16</p>

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

<p>At least how many bits is int?</p>

A

<p>16</p>

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

<p>At least how many bits is long?</p>

A

<p>32</p>

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

<p>At least how many bits is long long?</p>

A

<p>64</p>

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

<p>What is STL array?</p>

A

<p>STL array is fixed size array implementation from the standard library</p>

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

<p>What are the advantages of STL array over C array?</p>

A

<p>STL array doesn't degenerate to pointer when passed to function and it knows it's size</p>

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

<p>Where is STL array stored on the stack or on the heap?</p>

A

<p>On the stack</p>

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

<p>What does the const member function do?</p>

A

<p>1) Function declared const can be called for any object const or non const object<br></br>2) It doesn't allow modification on the object which calls them</p>

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

<p>What is an lambda function?</p>

A

<p>Short snippets of code that <br></br>1) Not worth naming<br></br>2) Not reused</p>

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

<p>Write to list lambda function syntax?</p>

A

<p>[ capture list ] (parameters) -> return-type <br></br>{ <br></br> method definition<br></br>}</p>

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

<p>What are lambda functions benefits?</p>

A

<p>1) They have application with generic functions like std::for_each, because it's not appropriate to create a new class for a specific algorithm.<br></br>2) Zero cost abstraction<br></br>3) Code becomes compact, structured, expressive.</p>

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

<p>When is the notion of invariant applied?</p>

A

<p>It is central to the design of classes.</p>

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

<p>What type of language is C++ (compiled or not compiled).</p>

A

<p>Compiled.</p>

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

<p>What are the steps for generating a C++ program?</p>

A

<p>1) Source text is processed by a compiler producing object files.<br></br>2) Object files are linked together producing executable file.</p>

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

<p>Is a C++ program compiled on one computer portable on another?</p>

A

<p>No, an executable C++ programs is created for specific hardware/system combination.</p>

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

<p>When we talk about portability of C++ program what do we mean?</p>

A

<p>Portability of source code. That is the source code could be successfully compiled and run on a variety of systems.</p>

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

<p>What is statically type language?</p>

A

<p>The type of every entity (object, value, name, expression) must be known to the compiler at its point of use.</p>

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

<p>What does the type of object determine?</p>

A

<p>The set of operations applicable to it and set of possible values.</p>

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

<p>What does {} indicate in C++?</p>

A

<p>Grouping</p>

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

<p>What does // indicate in C++?</p>

A

<p>Comment</p>

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

<p>What is main function?</p>

A

<p>Every program must have exactly one main function, it's where the program starts its execution.</p>

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

<p>What does non-zero value returned from main mean?</p>

A

<p>That the program has failed in some way.</p>

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

<p>What is a string literal?</p>

A

<p>A sequence of characters surrounded by double quotes.</p>

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

<p>What is a declaration?</p>

A

<p>1) A declaration is a statement that introduces a name to the program.<br></br>2) A declaration specifies the type of the name to inform the compiler what kind of entity the name refers to<br></br></p>

<p>It specifies all that's needed to use a function or a type.</p>

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

<p>What is an object?</p>

A

<p>An object is some memory that holds a value of some type.</p>

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

<p>What is a value?</p>

A

<p>A value is a set of bits interpreted according to a type.</p>

44
Q

<p>What is a variable?</p>

A

<p>A variable is a named object.</p>

45
Q

<p>What does sizeof operator do?</p>

A

<p>Determines the size of a type.</p>

46
Q

<p>What does const mean?</p>

A

<p>"I promise not to change this value"</p>

47
Q

<p>What does constexpr mean?</p>

A

<p>"Evaluated at compile time"</p>

48
Q

<p>What does switch do?</p>

A

<p>Tests a value against a set of constants.</p>

49
Q

<p>In declarations what does [] mean?</p>

A

<p>Array of</p>

50
Q

<p>In declarations what does * mean?</p>

A

<p>"pointer to"</p>

51
Q

<p>In a declaration what does & mean?</p>

A

<p>"reference to"</p>

52
Q

<p>What are &, * and [] called in a declaration?</p>

A

<p>Declarator operators.</p>

53
Q

<p>Which types we call user defined?</p>

A

<p>Those that can be built from built-in types, const modifier, and declarator operators.</p>

54
Q

<p>Why do we want to keep representation inaccessible to users?</p>

A

<p>1) To ease use<br></br>2) Guarantee consistent use of the data<br></br>3) Allows us later improve representation</p>

55
Q

<p>With what is the interface of a class defined?</p>

A

<p>With public members.</p>

56
Q

<p>How are private members accessible?</p>

A

<p>Only through a public interface.</p>

57
Q

<p>What is the basic technique for handling varying amounts of information in C++?</p>

A

<p>A fixed-size handle referring to a variable amount of data "elsewhere" (e.g., on the free store allocated by new)</p>

58
Q

<p>What do we call a constructor?</p>

A

<p>A function with the same name as the class.</p>

59
Q

<p>How is a constructor different from than ordinary function for the initialization of an object?</p>

A

<p>A constructor is guaranteed to be used to initialize objects of its class. Thus, eliminates the problem of uninitialized variables for a class.</p>

60
Q

<p>What is the purpose of enumerators?</p>

A

<p>To represent small sets of integer values. They make code more readable and less error-prone.</p>

61
Q

<p>With what C++ represent interfaces?</p>

A

<p>With declarations.</p>

62
Q

<p>What does declaration do?</p>

A

<p>It specifies all that's needed to use a function or a type.</p>

63
Q

<p>What is the link between declaration and definition?</p>

A

<p>A declaration must also have a definition somewhere but it can be in another place (In a cpp file, in library, etc.).</p>

64
Q

<p>Why is separate compilation used in C++?</p>

A

<p>To minimize compilation time and to strictly enforce separation of logically distinct parts of a program.</p>

65
Q

<p>What is the advantage of defining function inside a class?</p>

A

<p>It inline by default.</p>

66
Q

<p>What does inline function mean?</p>

A

<p>It replaces function call with the function body.</p>

67
Q

<p>What does inline function mean?</p>

A

<p>It replaces function call with the function body.</p>

68
Q

<p>What does a!=b translate to?</p>

A

<p>operator!=(a,b).</p>

69
Q

<p>What is a container?</p>

A

<p>An object holding a collection of elements.</p>

70
Q

<p>How is a destructor named?</p>

A

<p>Name of the class + prefix ~</p>

71
Q

<p>What is the purpose of destructor?</p>

A

<p>To ensure that memory allocated by the constructor is deallocated.</p>

72
Q

<p>What is handle-to-data model?</p>

A

<p>A method used for managing data that can vary in size during the lifetime of an object.</p>

73
Q

<p>What is the defining characteristic of concrete types?</p>

A

<p>It's representation is part of its definition.</p>

74
Q

<p>What is the defining characteristic of abstract class?</p>

A

<p>Implementation details are insulated from the user.</p>

75
Q

<p>What does the word virtual mean?</p>

A

<p>"may be redefined later in a class derived from this one"</p>

76
Q

<p>What does pure virtual function entail?</p>

A

<p>1. That the class is abstract<br></br>2. The function must be defined in some derived class</p>

77
Q

<p>What is virtual function table or vtbl?</p>

A

<p>During polymorphism an object must contain extra information to allow it to select the right function to call at runtime. Each class has it's own virtual function table. When a virtual function is called the compiler converts it into an index into a table of pointers to functions (vtbl).</p>

78
Q

<p>What is the space and performance overhead of virtual functions?</p>

A

<p>1) Performance within 25% to normal function calls<br></br>2) Overhead one pointer per object & one vtbl for each class</p>

79
Q

<p>When does copy elision apply?</p>

A

<p>The compiler can omit copy constructor, resulting in zero-copy pass-by-value semantics.</p>

80
Q

<p>What is a resource?</p>

A

<p>A resource is something that must be acquired and later (explicitly or implicitly) released</p>

81
Q

<p>What do we call a task?</p>

A

<p>A computation that can be potentially executed concurrently</p>

82
Q

<p>When talking about the C++ standard what we mean by implementation defined?</p>

A

<p>Many things are deemed implementation-defined by the standard. Meaning each implementation must provide a specific, well-defined behavior for a constructor: <br></br>unsigned char c1 = 64 // well defined: a char has at least 8 bits<br></br>unsigned char c2 = 1256 // implementation-defined: trunctuation if a char has only 8 bits</p>

83
Q

<p>When talking about the C++ standard what do we mean by unspecified behavior?</p>

A

<p>A range of possible behavior is acceptable, but the implementor is not obliged to specify which actually occur. Deciding for something to be unspecified is that the exact behavior is unpredictable for some reason.</p>

84
Q

<p>What is an undefined behavior?</p>

A

<p>No reasonable behavior is required by an implementation. Ex. Accessing allocated memory out of bounds.</p>

85
Q

<p>What is the difference between hosted and freestanding implementation?</p>

A

<p>A hosted implementation includes all the standard library facilities as described in the standard. A freestanding implementation may provide a fewer std facilities and a few headers must be provided...</p>

86
Q

<p>What is ASCII abbreviation?</p>

A

<p>American standard code for information interchange</p>

87
Q

<p>What do we need for x = y + f(2) to make sense?</p>

A

<p>The names x, y and f must be suitably declared. The programmer must specify that x, y, and f exist and that they are of types for which =, +, and () are meaningful.</p>

88
Q

<p>What do we mean by name?</p>

A

<p>Every name(identifier) in a C++ program has a type associated with it. This type determines the operations that can be applied to the name and how such operations are interpreted.</p>

89
Q

<p>Which types are called integral types?</p>

A

<p>The boolean, character and integer types are called integral types.</p>

90
Q

<p>Which types are called arithmetic types?</p>

A

<p>The integral and floating-point types are collectively called arithmetic types.</p>

91
Q

<p>Which types are called user-defined?</p>

A

<p>Enumerations and classes (because they must be defined by users)</p>

92
Q

<p>Which types are called built-in types?</p>

A

<p>Fundamental types, pointers, and references.</p>

93
Q

<p>What values can a boolean have?</p>

A

<p>True and False.</p>

94
Q

<p>Why is boolean used?</p>

A

<p>To express the result of logical operations</p>

95
Q

<p>Do integers implicitly convert to bool values and if so how?</p>

A

<p>Yes, nonzero integers convert to true and 0 converts to false</p>

96
Q

<p>Do pointers implicitly convert to bools if so how?</p>

A

<p>Yes, a non-null pointer converts to true. Pointers with the value nullptr convert to false.</p>

97
Q

<p>What does _t denote?</p>

A

<p>An alias type</p>

98
Q

<p>What is character literal?</p>

A

<p>A character literal is a single character enclosed in single quotes</p>

99
Q

<p>In what forms does integer type comes in?</p>

A

<p>"plain" int, signed int and unsigned int</p>

100
Q

<p>In what sizes does integers come?</p>

A

<p>short, "plain" int, long int, long long int</p>

101
Q

<p>What are plain ints always?</p>

A

<p>Signed</p>

102
Q

<p>Name the integer literals?</p>

A

<p>Decimal, Octal, Hexadecimal</p>

103
Q

<p>How many floating point types are there?</p>

A

<p>float (single precision), double (double precision), and long double (extended precision)</p>

104
Q

<p>What is floating point literal by default?</p>

A

<p>Double</p>

105
Q

<p>When is the void type used?</p>

A

<p>When we want to specify that a function doesn't return a value. As a base type for pointers to objects of unknown type.</p>