C++ Intro Flashcards
C++ but before reading the codebase or any advanced books (156 cards)
What does it mean that C++ is a “compiled language”?
It means the compiler takes object files, and turns them into executables.
What does it mean that C++ is “statically-typed”?
It means that the type of every object must be known to the compiler when it’s used.
What is a “built-in type”?
It’s one that can be built from the fundamental types.
What is a “user-defined type”?
It’s one that is built out of other types using abstraction mechanisms.
Give two examples of user-defined types.
Classes, enums.
How does the compiler handle virtual functions?
It creates the “virtual function table”, a table of pointers to functions.
What is it called when you do like: #indef FOO_BAR_BAZ_H__ #define FOO_BAR_BAZ_H__ … #endif // FOO_BAR_BAZ_H__
It’s called an include guard.
Why would you use an include guard?
To prevent the same header file from being included multiple times during compilation.
What are #ifndef, #define, and #endif called?
They are called “preprocesssor directives”
What does the “extern keyword mean” e.g. extern const int foo?
You use it in header files to say “I have this variable”. It’s up to the source file to define it.
How much memory is allocated when you put “extern” in your header file?
None.
What happens if you declare an extern variable in your header file, and then don’t define it in your source file?
You get a linker error like “unresolved external symbol”?
Why isn’t the extern keyword used for class declarations?
Because a class is a type, not a variable – when you say “class” you are just defining the type, not instantiating a specific variable.
What does the static keyword do?
It is similar to “private” in Java, but it’s about file scope – which files can access the property. Static means that only this file can access them. This is called “internal linkage”.
What does “internal linkage” mean and how do you indicate it?
It means the identifier is only visible in the source file where it is included. You indicate it with the “static” keyword.
Why is almost everything in a header file static?
Because you don’t need other files to be able to see those properties, just the source file.
Would you declare a public interface function as static?
No, you want every file to be able to see it, not just the source file.
What does it mean when a variable definition – not just declaration – is static?
This is declaring a singleton, ensuring it is only created once.
Under what two circumstances is there code in the header file rather than declarations?
You would declare small inline functions that you want inserted directly at the call site, to eliminate function call overhead. And you would declare templates, since the compiler needs the complete definition so it can generate code wherever the template is used.
What is the difference between include and import?
Include processes the complete text of the file every time it’s included, and the order matters. Import is just done once.
What are the things that you import called?
Modules
How do you define a module?
You put “module;” at the top of the file, and then “export module ModuleName”.
What version of C++ introduced modules?
C++ 20.
What is a namespace?
A namespace is something you use to group declarations together without worrying about naming conflicts.