Advertisement
Guest User

Untitled

a guest
Oct 11th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.80 KB | None | 0 0
  1.  
  2. CrallyToday at 10:53 AM
  3. Quiz for advanced. You're expected to not google answers or compile code snippets to determine validity. Your answer latency will be a factor in your score. Let me know when you're ready to begin.
  4. cutekoToday at 10:54 AM
  5. im on mobile is thay okay?
  6. CrallyToday at 10:54 AM
  7. So long as you can answer the questions
  8. cutekoToday at 10:54 AM
  9. okay
  10. CrallyToday at 10:54 AM
  11. Ready?
  12. cutekoToday at 10:54 AM
  13. ready as you are
  14. CrallyToday at 10:55 AM
  15. 1.) What is the difference between a declaration and a definition?
  16. cutekoToday at 10:55 AM
  17. declaration is the name and the type
  18. definition includes initialization
  19. CrallyToday at 10:56 AM
  20. Could you elaborate a bit? What does a defintion consists of that a declaration doesn't?
  21. cutekoToday at 10:57 AM
  22. definition must include initialization for pod type and class type and body for functions.
  23. declaration is basically telling the compiler that this variable exist in that form;
  24. CrallyToday at 10:59 AM
  25. What did you mean by "must include initialization"?
  26. cutekoToday at 11:01 AM
  27. int a; // declaration
  28. int a = 42;// definition
  29. void fn();// declaration
  30. void fn(){} // definition
  31. struct T; //declaration
  32. struct T{};// definition
  33. CrallyToday at 11:01 AM
  34. so just to clarify, this int a; is a declaration and not a defintion?
  35. cutekoToday at 11:02 AM
  36. yes
  37. CrallyToday at 11:02 AM
  38. Alright, moving on
  39. 2.) What purpose do header guards serve?
  40. cutekoToday at 11:03 AM
  41. prevent redefinition of whats inside the #ifndef block
  42. CrallyToday at 11:04 AM
  43. In what scenario?
  44. cutekoToday at 11:04 AM
  45. or whats under #pragma once
  46. when the header is included many times in the translation unit
  47. CrallyToday at 11:04 AM
  48. Alright, next question
  49. 3.) What does the volatile keyword do?
  50. cutekoToday at 11:05 AM
  51. volatile makes a variable non optimizable
  52. CrallyToday at 11:05 AM
  53. Good enough
  54. 4.) What is the strict aliasing rule?
  55. cutekoToday at 11:06 AM
  56. wait is that a thing? maybe i know it but not the name
  57. CrallyToday at 11:06 AM
  58. We can go onto the next question if you'd like
  59. cutekoToday at 11:07 AM
  60. ok then
  61. CrallyToday at 11:07 AM
  62. 5.) What purpose do unnamed namespaces serve?
  63. cutekoToday at 11:07 AM
  64. for disambiguation
  65. CrallyToday at 11:07 AM
  66. Explain
  67. cutekoToday at 11:08 AM
  68. for example your inside a namespace x
  69. inside x there a send function
  70. in order to use the posix send function you need to use ::send
  71. because using send will resolve to x::send
  72. CrallyToday at 11:10 AM
  73. Well yes, but you may have misread my question. I'm asking specifically about unnamed namespaces; I.E. namespaces that do not have a name.(edited)
  74. cutekoToday at 11:11 AM
  75. oh i see
  76. i think anything under it will be automatically be named as if it is in top level even if it is under a namespace
  77. CrallyToday at 11:13 AM
  78. Ok, but why is it useful? What does it do?
  79. cutekoToday at 11:18 AM
  80. namespace nnn{
  81. namespace {
  82. int x;
  83. }
  84. }
  85. in that case x will just be x
  86. not nnn::x
  87. CrallyToday at 11:19 AM
  88. Alright, I understand what you're saying
  89. We can move on
  90. cutekoToday at 11:20 AM
  91. everything inside unamed will also be in the top level for that translation unit
  92. okay
  93. CrallyToday at 11:20 AM
  94. 6.) Whan auto is used in lambda parameters and function return types, what kind of type deduction is taking place?
  95. cutekoToday at 11:22 AM
  96. for the parameter same deduction would apply as it there was a template argument
  97. for return type it would be based on the deduction of the return expression
  98. CrallyToday at 11:24 AM
  99. I'm not asking about the type deduced. In C++, there are different kinds of type deduction, such as auto, decltype, template, etc.(edited)
  100. cutekoToday at 11:24 AM
  101. & && will still apply
  102. CrallyToday at 11:24 AM
  103. lambda paramters and function return types use a specific type deduction, which is it?
  104. cutekoToday at 11:25 AM
  105. for parameter its template for return type its decltype
  106. CrallyToday at 11:25 AM
  107. alright, moving on
  108. 7.) What is the primary difference between template type deduction and auto type deduction?
  109. cutekoToday at 11:28 AM
  110. auto deduction doesnt need template
  111. the deduction ruels are the same
  112. CrallyToday at 11:28 AM
  113. Alright
  114. 8.) Say you have a vector of objects of copyable type Foo. When the vector grows and allocates another block of memory, it uses Foo’s copy constructor to copy the objects over to the new memory. How would you get vector to move the objects instead?
  115. cutekoToday at 11:30 AM
  116. if Foo is not trivially movable
  117. vector will use Foo(Foo&&)
  118. ie when move constructor is specified
  119. CrallyToday at 11:31 AM
  120. I'll ask again, how would you get vector to move the objects instead?
  121. cutekoToday at 11:34 AM
  122. you need to make Foo(Foo&&) constructor for the vector to use move
  123. oh i think i know what you meant
  124. CrallyToday at 11:35 AM
  125. Alright, moving on
  126. 9.) Explain the ‘Diamond Problem’ and C++’s solution.
  127. cutekoToday at 11:37 AM
  128. Diamond problem is when you are inheriting common bases...both bases constructor will called and there will be 1 bases in the derived class layout
  129. to solve this you need to specify virtual in the common base
  130. CrallyToday at 11:38 AM
  131. You need to be more specific, it's very difficult to understand what you're trying to say with " when you are inheriting common bases...both bases constructor will called and there will be 1 bases in the derived class layout"
  132. cutekoToday at 11:40 AM
  133. the will be a separate memory space for common base classes on the derived class hence each common base constructor will also be called
  134. CrallyToday at 11:41 AM
  135. Just to clarify, you're saying the diamond problem is when two classes seprately inherit from a single base class, yes?
  136. cutekoToday at 11:41 AM
  137. ill show you a uml
  138. Base <|-- DerivedA
  139. Base <|-- DerivedB
  140. DrivedA <|-- DerivedC
  141. DerivedB <|-- DerivedC
  142. CrallyToday at 11:42 AM
  143. Alright, so how does C++ attempt to solve this?
  144. cutekoToday at 11:43 AM
  145. inherit Base as virtual Base
  146. atleast on DerivedA or DerivedB
  147. CrallyToday at 11:44 AM
  148. And what will that do?
  149. cutekoToday at 11:45 AM
  150. Compiler will unify the Base as if its only 1 instance
  151. so only one memory space for the base hence 1 construction call
  152. for the Base
  153. CrallyToday at 11:46 AM
  154. Alright, let's move on
  155. 10.) Does the following benefit from moving rather than being copied? Why or Why not?
  156. struct IntContainer
  157. {
  158. int a, b, c, d, x, y, z, w;
  159. }
  160. cutekoToday at 11:46 AM
  161. no
  162. there are no resources here thats needed to be moved
  163. CrallyToday at 11:47 AM
  164. 11.) What effect does marking a function as constexpr have?
  165. cutekoToday at 11:48 AM
  166. expression will be resolved at compile time
  167. CrallyToday at 11:48 AM
  168. So it means the function will be evaluated at compile time?
  169. cutekoToday at 11:48 AM
  170. yes
  171. CrallyToday at 11:49 AM
  172. Always?
  173. cutekoToday at 11:50 AM
  174. yes i think compiler will complain if there are thing that are not constexpr is used inside the constexpr function
  175. CrallyToday at 11:50 AM
  176. Alright, I'm gonna wrap this up and get your answers examined.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement