C++ Core Flashcards
(309 cards)
What are the 3 different categories of data types present in C++?
Fundamental data types, User defined data types, Derived data types
Name the C++ fundamental data types
- Boolean type (bool)
- Character types (char, wchar_t)
- Integer types (int, long long …)
- Floating-point types (double, long double ….)
- Void
What is the void type?
- Type with an empty set of values (no value applies to it).
- Incomplete type that cannot be completed.
What is an incomplete type?
A type that is not defined or void type.
What is nullptr_t?
Answer:
- nullptr_t solves previous ambiguity problems with NULL
- nullptr_t is the type of the nullptr literal.
- It is a distinct type that it’s not itself a pointer type.
Read more:
https://dzone.com/articles/what-exactly-nullptr-is-in-c
What RAII abbreviation means?
Resource Acquisition In Initialization
What is RAII Intent?
Answers:
- To guarantee the release of a resource at the end of scope.
- To guarantee no memory leaks
Read more:
http://www.vishalchovatiya.com/7-advance-cpp-concepts-idiom-examples-you-should-know/#Return-Type-Resolver
What is example RAII Implementation?
Answer:
- Wrap resource into a class
- Resource acquired in the constructor immediately after it’s allocation
- Destructor automatically releases resource
- Resource used via interface
Read more:
http://www.vishalchovatiya.com/7-advance-cpp-concepts-idiom-examples-you-should-know/#Return-Type-Resolver
Why RAII is imporant?
Answer:
- To not forget to release resource.
- If a function returns early (throws, returns, etc…) resource may be leaked.
Read more:
http://www.vishalchovatiya.com/7-advance-cpp-concepts-idiom-examples-you-should-know/#Return-Type-Resolver
What are RAII usecases?
Answer:
In acquisition/release of resource with:
1)new/delete (memory)
2)lock/unlock (mutex)
3)open/close (file)
4)and others
Read more:
http://www.vishalchovatiya.com/7-advance-cpp-concepts-idiom-examples-you-should-know/#Return-Type-Resolver
What is the intent of return type resolver idiom?
Answer:
To deduce the type of the object being initialized or assigned to.
Read more:
http://www.vishalchovatiya.com/7-advance-cpp-concepts-idiom-examples-you-should-know/#Return-Type-Resolver
What is NULL?
NULL is a MACRO that is evaluated to integer with value 0
What is the intent of Type Erasure?
Answer:
To create generic container that can handle variety of concrete types.
What we refer to when we say the implementation’s data model?
The sizes of the fundamental data types that are made by each implementation is referred to as the data model.
What are the four data models that found wide acceptance?
int/long/pointer notation (size in bytes)
32 bit systems:
LP32 (2/4/4 Win16) or ILP32 (4/4/4 Win32, Unix)
64 bit systems
LP64 (4/4/8 Win64) or ILP64 (4/8/8 Unix)
What are the integer types modifiers?
Signedness: signed (default) and unsigned.
Size: short (at least 16 bits) and long (at least 32 bits) and long long (C++11 at least 64 bits).
When integer types overflow is undefined?
When you overflow a signed integer.
At least how many bits is short?
16
At least how many bits is int?
16
At least how many bits is long?
32
At least how many bits is long long?
64
What is STL array?
STL array is fixed size array implementation from the standard library
What are the advantages of STL array over C array?
STL array doesn’t degenerate to pointer when passed to function and it knows it’s size
Where is STL array stored on the stack or on the heap?
On the stack