Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CrallyToday at 10:53 AM
- 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.
- cutekoToday at 10:54 AM
- im on mobile is thay okay?
- CrallyToday at 10:54 AM
- So long as you can answer the questions
- cutekoToday at 10:54 AM
- okay
- CrallyToday at 10:54 AM
- Ready?
- cutekoToday at 10:54 AM
- ready as you are
- CrallyToday at 10:55 AM
- 1.) What is the difference between a declaration and a definition?
- cutekoToday at 10:55 AM
- declaration is the name and the type
- definition includes initialization
- CrallyToday at 10:56 AM
- Could you elaborate a bit? What does a defintion consists of that a declaration doesn't?
- cutekoToday at 10:57 AM
- definition must include initialization for pod type and class type and body for functions.
- declaration is basically telling the compiler that this variable exist in that form;
- CrallyToday at 10:59 AM
- What did you mean by "must include initialization"?
- cutekoToday at 11:01 AM
- int a; // declaration
- int a = 42;// definition
- void fn();// declaration
- void fn(){} // definition
- struct T; //declaration
- struct T{};// definition
- CrallyToday at 11:01 AM
- so just to clarify, this int a; is a declaration and not a defintion?
- cutekoToday at 11:02 AM
- yes
- CrallyToday at 11:02 AM
- Alright, moving on
- 2.) What purpose do header guards serve?
- cutekoToday at 11:03 AM
- prevent redefinition of whats inside the #ifndef block
- CrallyToday at 11:04 AM
- In what scenario?
- cutekoToday at 11:04 AM
- or whats under #pragma once
- when the header is included many times in the translation unit
- CrallyToday at 11:04 AM
- Alright, next question
- 3.) What does the volatile keyword do?
- cutekoToday at 11:05 AM
- volatile makes a variable non optimizable
- CrallyToday at 11:05 AM
- Good enough
- 4.) What is the strict aliasing rule?
- cutekoToday at 11:06 AM
- wait is that a thing? maybe i know it but not the name
- CrallyToday at 11:06 AM
- We can go onto the next question if you'd like
- cutekoToday at 11:07 AM
- ok then
- CrallyToday at 11:07 AM
- 5.) What purpose do unnamed namespaces serve?
- cutekoToday at 11:07 AM
- for disambiguation
- CrallyToday at 11:07 AM
- Explain
- cutekoToday at 11:08 AM
- for example your inside a namespace x
- inside x there a send function
- in order to use the posix send function you need to use ::send
- because using send will resolve to x::send
- CrallyToday at 11:10 AM
- 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)
- cutekoToday at 11:11 AM
- oh i see
- i think anything under it will be automatically be named as if it is in top level even if it is under a namespace
- CrallyToday at 11:13 AM
- Ok, but why is it useful? What does it do?
- cutekoToday at 11:18 AM
- namespace nnn{
- namespace {
- int x;
- }
- }
- in that case x will just be x
- not nnn::x
- CrallyToday at 11:19 AM
- Alright, I understand what you're saying
- We can move on
- cutekoToday at 11:20 AM
- everything inside unamed will also be in the top level for that translation unit
- okay
- CrallyToday at 11:20 AM
- 6.) Whan auto is used in lambda parameters and function return types, what kind of type deduction is taking place?
- cutekoToday at 11:22 AM
- for the parameter same deduction would apply as it there was a template argument
- for return type it would be based on the deduction of the return expression
- CrallyToday at 11:24 AM
- I'm not asking about the type deduced. In C++, there are different kinds of type deduction, such as auto, decltype, template, etc.(edited)
- cutekoToday at 11:24 AM
- & && will still apply
- CrallyToday at 11:24 AM
- lambda paramters and function return types use a specific type deduction, which is it?
- cutekoToday at 11:25 AM
- for parameter its template for return type its decltype
- CrallyToday at 11:25 AM
- alright, moving on
- 7.) What is the primary difference between template type deduction and auto type deduction?
- cutekoToday at 11:28 AM
- auto deduction doesnt need template
- the deduction ruels are the same
- CrallyToday at 11:28 AM
- Alright
- 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?
- cutekoToday at 11:30 AM
- if Foo is not trivially movable
- vector will use Foo(Foo&&)
- ie when move constructor is specified
- CrallyToday at 11:31 AM
- I'll ask again, how would you get vector to move the objects instead?
- cutekoToday at 11:34 AM
- you need to make Foo(Foo&&) constructor for the vector to use move
- oh i think i know what you meant
- CrallyToday at 11:35 AM
- Alright, moving on
- 9.) Explain the ‘Diamond Problem’ and C++’s solution.
- cutekoToday at 11:37 AM
- 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
- to solve this you need to specify virtual in the common base
- CrallyToday at 11:38 AM
- 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"
- cutekoToday at 11:40 AM
- the will be a separate memory space for common base classes on the derived class hence each common base constructor will also be called
- CrallyToday at 11:41 AM
- Just to clarify, you're saying the diamond problem is when two classes seprately inherit from a single base class, yes?
- cutekoToday at 11:41 AM
- ill show you a uml
- Base <|-- DerivedA
- Base <|-- DerivedB
- DrivedA <|-- DerivedC
- DerivedB <|-- DerivedC
- CrallyToday at 11:42 AM
- Alright, so how does C++ attempt to solve this?
- cutekoToday at 11:43 AM
- inherit Base as virtual Base
- atleast on DerivedA or DerivedB
- CrallyToday at 11:44 AM
- And what will that do?
- cutekoToday at 11:45 AM
- Compiler will unify the Base as if its only 1 instance
- so only one memory space for the base hence 1 construction call
- for the Base
- CrallyToday at 11:46 AM
- Alright, let's move on
- 10.) Does the following benefit from moving rather than being copied? Why or Why not?
- struct IntContainer
- {
- int a, b, c, d, x, y, z, w;
- }
- cutekoToday at 11:46 AM
- no
- there are no resources here thats needed to be moved
- CrallyToday at 11:47 AM
- 11.) What effect does marking a function as constexpr have?
- cutekoToday at 11:48 AM
- expression will be resolved at compile time
- CrallyToday at 11:48 AM
- So it means the function will be evaluated at compile time?
- cutekoToday at 11:48 AM
- yes
- CrallyToday at 11:49 AM
- Always?
- cutekoToday at 11:50 AM
- yes i think compiler will complain if there are thing that are not constexpr is used inside the constexpr function
- CrallyToday at 11:50 AM
- Alright, I'm gonna wrap this up and get your answers examined.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement