1. Home
  2. Explore
  3. Computer Science
  4. Bjarne Stroustrup Technology Lecture

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Bjarne Stroustrup Technology Lecture

  • 84Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: C++ Design Goals

Which set of priorities best describes the intended domain of C++ in the lecture?

84 questions

  1. 1

    Which set of priorities best describes the intended domain of C++ in the lecture?

    1. A

      Providing one specialized language for scientific calculations and business records

    2. B

      Replacing hardware-oriented programming with a runtime-managed virtual machine

    3. C

      Making web applications with the shortest possible code and few implementation details

    4. D

      Building efficient abstractions for systems, resource-constrained, and large-scale software

    Correct answer
    D

    Building efficient abstractions for systems, resource-constrained, and large-scale software

    Explanation

    The lecture characterizes C++ as a language for efficient and elegant abstractions, especially in systems software, resource-constrained applications, and large systems.

  2. 2

    Why does the lecturer consider type safety important in C++?

    1. A

      It ensures that every operation has the same execution time on every machine

    2. B

      It removes the need to understand what operations a program performs

    3. C

      It guarantees that every program will use less memory than an equivalent untyped program

    4. D

      It helps catch invalid uses of values while working within constraints such as performance and program size

    Correct answer
    D

    It helps catch invalid uses of values while working within constraints such as performance and program size

    Explanation

    The lecture presents type safety as a key goal, while recognizing that improving it must be balanced against constraints such as performance and program size.

  3. 3

    Why are predictable execution times especially important in hard real-time systems?

    1. A

      Predictability ensures that every operation uses the smallest possible amount of memory

    2. B

      Some operations must finish within known time limits, so unpredictable operations may be unacceptable

    3. C

      A predictable program can be compiled without checking its types

    4. D

      Real-time systems must avoid using any data types that represent hardware

    Correct answer
    B

    Some operations must finish within known time limits, so unpredictable operations may be unacceptable

    Explanation

    The speaker explains that hard real-time systems may require operations to have predictable, usually bounded, execution times.

  4. 4

    What does the lecture mean by wanting code complexity to be proportional to task complexity?

    1. A

      The code should be as complex as the programmer is able to manage

    2. B

      A simple task should not require unnecessarily elaborate code, while harder tasks may justify more complexity

    3. C

      Complex tasks should be rewritten as simple tasks before they can be programmed

    4. D

      Every task should be implemented with the same number of statements

    Correct answer
    B

    A simple task should not require unnecessarily elaborate code, while harder tasks may justify more complexity

    Explanation

    The lecturer describes proportional complexity as an ideal: the code needed should reflect the actual difficulty of the task rather than adding avoidable complexity.

  5. 5

    Why does the lecturer argue that C++ should be friendly to novices as well as experts?

    1. A

      Expert-friendly languages cannot support efficient low-level programming

    2. B

      New users should be able to write any program without learning its concepts

    3. C

      A language that only experts can use effectively limits the number of people it can help

    4. D

      Novices need to avoid abstractions, so the language should exclude advanced features

    Correct answer
    C

    A language that only experts can use effectively limits the number of people it can help

    Explanation

    The speaker says that expert-friendliness is not enough if the language is hostile to novices or casual users who could otherwise benefit from it.

  6. 6

    Why does the lecture emphasize readable code even though C++ can also be written in difficult-to-read ways?

    1. A

      Human readability matters only for programs that do not interact with hardware

    2. B

      Readable code is guaranteed automatically whenever a program compiles

    3. C

      The language should make clear, human-readable code possible, even if it cannot prevent every poor style

    4. D

      The language should sacrifice performance whenever that makes code shorter

    Correct answer
    C

    The language should make clear, human-readable code possible, even if it cannot prevent every poor style

    Explanation

    The lecturer treats readability as an important goal, while acknowledging that C++—like any language—can still be used to write ugly code.

  7. 7

    What trade-off does the lecturer identify between C++ and languages aimed at simpler application development?

    1. A

      C++ avoids performance concerns in order to minimize the amount of code

    2. B

      C++ is intended to replace every language used for specialized application domains

    3. C

      C++ emphasizes real-world systems constraints rather than being the simplest language for every application

    4. D

      C++ is designed only for web applications, while other languages handle systems work

    Correct answer
    C

    C++ emphasizes real-world systems constraints rather than being the simplest language for every application

    Explanation

    The lecture says C++ is not intended to be the simplest language for all purposes; it aims to remain useful under real-world systems constraints.

  8. 8

    What does the lecturer mean by saying that software often outlives hardware?

    1. A

      Programs are generally discarded before the machines they run on

    2. B

      Software may remain in use for many years, so language and system design must account for long-term maintenance

    3. C

      Software longevity makes compatibility between program versions unnecessary

    4. D

      Hardware can only be used after all associated software has been replaced

    Correct answer
    B

    Software may remain in use for many years, so language and system design must account for long-term maintenance

    Explanation

    The speaker uses the long life of software to motivate attention to long-term systems design and compatibility.

  9. 9

    Why does the lecturer describe C++ as useful for work in fields such as high-energy physics?

    1. A

      High-energy physics requires no knowledge beyond general-purpose programming

    2. B

      C++ is designed exclusively for particle-physics calculations

    3. C

      C++ programming automatically qualifies someone as a theoretical physicist

    4. D

      Programming can provide a way to contribute to technical projects across many fields

    Correct answer
    D

    Programming can provide a way to contribute to technical projects across many fields

    Explanation

    The speaker observes that programming can be an effective route into interesting projects in many fields, including high-energy physics.

  10. 10

    Why does the lecturer say that C++ must retain the ability to work close to hardware?

    1. A

      All C++ programs must directly manipulate hardware registers

    2. B

      Low-level programming is possible only when a language has no type system

    3. C

      It is intended to support low-level work as well as abstractions built above that level

    4. D

      Hardware access makes higher-level abstractions unnecessary

    Correct answer
    C

    It is intended to support low-level work as well as abstractions built above that level

    Explanation

    The lecture presents C++ as aiming to support both direct, hardware-near programming and higher-level abstractions.

  11. 11

    What is the central idea behind C's memory model as described in the lecture?

    1. A

      It maps operations such as addition and memory access onto relatively direct hardware concepts

    2. B

      It prevents programmers from composing objects in memory

    3. C

      It represents every value as an object in a class hierarchy

    4. D

      It hides memory layout behind a mandatory garbage collector

    Correct answer
    A

    It maps operations such as addition and memory access onto relatively direct hardware concepts

    Explanation

    The lecturer praises C's relatively direct model: operations correspond to hardware actions, and objects can be laid out in memory in straightforward ways.

  12. 12

    What change in programming did Fortran represent, according to the lecture?

    1. A

      It was designed primarily to let business records communicate with physics programs

    2. B

      It introduced the first class hierarchy for representing related concepts

    3. C

      It replaced all hardware-oriented programming with automatic resource management

    4. D

      It raised programming from a machine-focused level toward a level organized around scientists' and engineers' problems

    Correct answer
    D

    It raised programming from a machine-focused level toward a level organized around scientists' and engineers' problems

    Explanation

    The lecturer describes Fortran as an early language that made programming more problem-focused for scientists and engineers rather than centered solely on the machine.

  13. 13

    What difficulty arose when many specialized programming languages developed?

    1. A

      Programs written for different domains could not easily combine their strengths or work together

    2. B

      Specialized languages could not perform calculations within their intended domains

    3. C

      Each language used exactly the same data representations and therefore lacked specialization

    4. D

      Scientists and business users were forced to write every program in machine code

    Correct answer
    A

    Programs written for different domains could not easily combine their strengths or work together

    Explanation

    The speaker explains that specialized languages could excel in different areas, but combining their capabilities was difficult because they could not readily communicate.

  14. 14

    What contribution does the lecture attribute to Simula?

    1. A

      It solved resource leaks by automatically collecting every kind of resource

    2. B

      It created the first language specifically for scientific numerical calculations

    3. C

      It established C's direct mapping between memory operations and hardware

    4. D

      It introduced the idea of letting programmers build their own abstractions using classes

    Correct answer
    D

    It introduced the idea of letting programmers build their own abstractions using classes

    Explanation

    The lecture credits Simula with the class concept, allowing programmers to define abstractions such as vectors, matrices, and records.

  15. 15

    How did the combination of C and Simula influence C++?

    1. A

      C's business-record features were combined with Simula's scientific-only operations

    2. B

      C's garbage collector was combined with Simula's machine-code-only interface

    3. C

      C's class hierarchy was combined with Simula's lack of data types

    4. D

      C's relatively direct hardware model was combined with Simula's class-based abstraction ideas

    Correct answer
    D

    C's relatively direct hardware model was combined with Simula's class-based abstraction ideas

    Explanation

    The lecturer describes C++ as bringing together C's direct relationship to hardware and Simula's facilities for classes and abstractions.

  16. 16

    Why were constructors and destructors important to the development of C++ abstractions?

    1. A

      They ensure that every class must inherit from another class

    2. B

      They provide a way to initialize objects and clean up resources associated with them

    3. C

      They automatically make every object shared among all program components

    4. D

      They allow programs to avoid defining how objects are represented

    Correct answer
    B

    They provide a way to initialize objects and clean up resources associated with them

    Explanation

    The lecture explains that an abstraction may need initialization when an object is created and cleanup when it is no longer needed.

  17. 17

    Why has backward compatibility been a constraint on changing C++?

    1. A

      Large existing codebases depend on old behavior, and developers do not want upgrades to break them

    2. B

      New language features cannot be implemented in a language with classes

    3. C

      Compatibility requires that every new program use the oldest available compiler

    4. D

      Old code cannot be analyzed or transformed by software tools

    Correct answer
    A

    Large existing codebases depend on old behavior, and developers do not want upgrades to break them

    Explanation

    The lecturer says that existing users often need old code to keep working, which makes removing old features or changing behavior difficult.

  18. 18

    What is meant by calling some old C++ features 'barnacles'?

    1. A

      They are optional libraries that cannot be used in systems programming

    2. B

      They are runtime errors caused only by garbage collection

    3. C

      They are newly added abstractions that eliminate the need for compatibility

    4. D

      They are legacy features that can complicate the language but are difficult to remove without breaking existing code

    Correct answer
    D

    They are legacy features that can complicate the language but are difficult to remove without breaking existing code

    Explanation

    The speaker uses the barnacle metaphor for historical complications that remain because users and organizations rely on existing behavior.

  19. 19

    Why does the lecturer argue that a completely new language might struggle to replace C++?

    1. A

      It would lack the established community, code, and infrastructure unless it could become embedded in them

    2. B

      Existing C++ programmers cannot learn any new language features

    3. C

      New languages cannot support low-level programming or efficient abstractions

    4. D

      A new language would necessarily have to use Java's design choices

    Correct answer
    A

    It would lack the established community, code, and infrastructure unless it could become embedded in them

    Explanation

    The lecturer says that a new language might have attractive properties but could fail quickly without access to the existing C++ community and infrastructure.

  20. 20

    Which group consists entirely of examples of resources that a program may need to acquire and later release?

    1. A

      Integers, class names, comments, and function declarations

    2. B

      Loops, predicates, type aliases, and arithmetic expressions

    3. C

      Arrays, algorithms, source files, and language standards

    4. D

      Memory, file handles, locks, and network connections

    Correct answer
    D

    Memory, file handles, locks, and network connections

    Explanation

    The lecture lists memory, file handles, locks, and communication connections as examples of resources that must be returned or released.

  21. 21

    What is a resource leak?

    1. A

      A situation in which a program releases a resource before acquiring it

    2. B

      A situation in which a program stores several values in one container

    3. C

      A situation in which a program uses a resource through a named abstraction

    4. D

      A situation in which a program fails to release a resource after it is finished using it

    Correct answer
    D

    A situation in which a program fails to release a resource after it is finished using it

    Explanation

    A leak occurs when a resource, such as memory or a file handle, is not returned after the program has finished with it.

  22. 22

    Why does the lecturer say that a resource should have a known owner?

    1. A

      Ownership allows every resource to be shared without tracking its users

    2. B

      Ownership ensures that a resource can never be passed between functions

    3. C

      Ownership clarifies which part of the program is responsible for releasing the resource

    4. D

      Ownership prevents an object from having a destructor

    Correct answer
    C

    Ownership clarifies which part of the program is responsible for releasing the resource

    Explanation

    The lecture identifies unclear responsibility for cleanup as a source of resource-management problems.

  23. 23

    Why can passing a raw pointer to another part of a program create a resource-management problem?

    1. A

      A raw pointer can represent only an object stored in a local variable

    2. B

      A raw pointer automatically records every part of the program that uses its object

    3. C

      A raw pointer always destroys its object as soon as it is passed

    4. D

      The pointer alone may not establish which part of the program owns and must release the object

    Correct answer
    D

    The pointer alone may not establish which part of the program owns and must release the object

    Explanation

    The speaker's shape example illustrates that passing a pointer does not by itself make responsibility for cleanup clear.

  24. 24

    How does a standard container such as a vector help manage the resources it uses?

    1. A

      It transfers ownership of its storage to the compiler permanently

    2. B

      It prevents the container from containing objects that need cleanup

    3. C

      It manages its internal storage and releases that storage when the container goes out of scope

    4. D

      It requires the caller to manually delete every element after each operation

    Correct answer
    C

    It manages its internal storage and releases that storage when the container goes out of scope

    Explanation

    The lecture explains that a container manages its storage and cleans it up when the container's lifetime ends.

  25. 25

    How can cleanup work correctly for a vector whose elements are themselves strings?

    1. A

      The compiler converts the vector and strings into a shared pointer automatically

    2. B

      The vector cleans up its storage, and each string in turn cleans up its own resources

    3. C

      The vector must ignore the strings because only the program can release them

    4. D

      Each string must release the vector's storage before it is destroyed

    Correct answer
    B

    The vector cleans up its storage, and each string in turn cleans up its own resources

    Explanation

    The lecture describes layered cleanup: the vector is responsible for its elements, and the elements' own destructors manage their resources.

  26. 26

    Why is manually writing cleanup code after operations that can return or throw an exception error-prone?

    1. A

      A return statement automatically releases only the most recently acquired resource

    2. B

      Manual cleanup can be used only for memory, not files or locks

    3. C

      An early exit can bypass cleanup statements that occur later in the function

    4. D

      Exceptions prevent destructors from running for local objects

    Correct answer
    C

    An early exit can bypass cleanup statements that occur later in the function

    Explanation

    The lecturer's example shows that returns and exceptions can make manually placed cleanup code easy to miss or get wrong.

  27. 27

    How does a local resource-managing object help when a function exits early?

    1. A

      It prevents the function from returning or throwing exceptions

    2. B

      It leaves cleanup to whichever function next receives a pointer to the object

    3. C

      Its destructor runs as its lifetime ends, so cleanup occurs on normal or exceptional exits

    4. D

      It stores the resource indefinitely so that no cleanup decision is needed

    Correct answer
    C

    Its destructor runs as its lifetime ends, so cleanup occurs on normal or exceptional exits

    Explanation

    The lecture relies on destructors to clean up local resources when control leaves a scope, including when an exception is thrown.

  28. 28

    What does 'resource acquisition is initialization' describe in the lecture?

    1. A

      Using a garbage collector to discover resources after they become unreachable

    2. B

      Initializing an object only after its resource has been manually deleted

    3. C

      Acquiring a resource as part of constructing an object that will release it during destruction

    4. D

      Acquiring every resource at program startup and releasing it only at program shutdown

    Correct answer
    C

    Acquiring a resource as part of constructing an object that will release it during destruction

    Explanation

    The lecture presents this idiom as tying a resource's lifetime to an object's lifetime: construction establishes the resource, and destruction cleans it up.

  29. 29

    Why does the lecturer describe exceptions as a useful error-handling mechanism when combined with destructors?

    1. A

      Exceptions guarantee that programs never encounter resource failures

    2. B

      Exceptions can report errors while destructors clean up local resources during the resulting exits

    3. C

      Exceptions make every resource available to every function automatically

    4. D

      Exceptions eliminate the need for constructors and object lifetimes

    Correct answer
    B

    Exceptions can report errors while destructors clean up local resources during the resulting exits

    Explanation

    The speaker links exceptions and destructors: errors can propagate while local resource-managing objects still clean up.

  30. 30

    When is a unique pointer a better fit than a shared pointer, as described in the lecture?

    1. A

      When the object must be managed without any ownership relationship

    2. B

      When many independent owners must keep the object alive together

    3. C

      When one part of the program is the sole owner of the object

    4. D

      When no part of the program should know the object's lifetime

    Correct answer
    C

    When one part of the program is the sole owner of the object

    Explanation

    The lecture recommends unique ownership when an object belongs to just one owner, avoiding unnecessary shared ownership.

  31. 31

    What happens to a shared pointer's use count as additional shared pointers refer to the same object?

    1. A

      The count stays fixed, and each pointer independently deletes the object

    2. B

      The count decreases, and the first pointer to be destroyed deletes the object

    3. C

      The count records how many bytes the object uses, not how many owners it has

    4. D

      The count increases, and the object is cleaned up when the final shared owner releases it

    Correct answer
    D

    The count increases, and the object is cleaned up when the final shared owner releases it

    Explanation

    The speaker explains that shared pointers track the number of owners and clean up the object when the count reaches zero.

  32. 32

    Why can shared ownership have a cost even when it prevents an object from being destroyed too early?

    1. A

      Every shared pointer copies the entire object whenever it is passed

    2. B

      The shared ownership count must be maintained, and that shared state can add overhead

    3. C

      Shared pointers prevent destructors from running

    4. D

      Every shared pointer requires a garbage collector to scan all program memory

    Correct answer
    B

    The shared ownership count must be maintained, and that shared state can add overhead

    Explanation

    The lecture notes that maintaining a shared use count adds work, particularly because the count is shared among users.

  33. 33

    Why does the lecturer caution against sharing an object when sharing is unnecessary?

    1. A

      An object with one owner cannot have a destructor

    2. B

      Shared ownership makes the object's type impossible to determine

    3. C

      Every unshared object must be stored on the free store

    4. D

      Shared state can impose coordination costs, especially in concurrent programs

    Correct answer
    D

    Shared state can impose coordination costs, especially in concurrent programs

    Explanation

    The speaker argues that shared resources can cost more than expected, particularly in concurrent systems, so unnecessary sharing should be avoided.

  34. 34

    Why should a function returning a newly created object generally return the object itself rather than a raw pointer to it?

    1. A

      Returning a raw pointer automatically makes the caller the unique owner

    2. B

      Returning an object prevents the caller from using its value

    3. C

      Returning an object preserves a clearer ownership model and avoids forcing callers to manage a raw pointer

    4. D

      Returning an object guarantees that the function never allocates storage

    Correct answer
    C

    Returning an object preserves a clearer ownership model and avoids forcing callers to manage a raw pointer

    Explanation

    The lecture recommends returning a new object as an object, rather than reintroducing unclear ownership and cleanup problems through a raw pointer.

  35. 35

    What is a limitation of using a reference return to avoid returning a large object by value?

    1. A

      A reference can be returned only from a function that has no local variables

    2. B

      A reference guarantees that the object will outlive every caller

    3. C

      A reference always copies the referred-to object before returning

    4. D

      A reference does not explain who owns the referred-to object or who must destroy it

    Correct answer
    D

    A reference does not explain who owns the referred-to object or who must destroy it

    Explanation

    The speaker points out that returning a reference may hide rather than solve the ownership and lifetime problem.

  36. 36

    What ownership role does the lecture assign to raw pointers and iterators?

    1. A

      They can refer to objects owned elsewhere rather than necessarily representing ownership themselves

    2. B

      They are the only safe way to store an object in a container

    3. C

      They always own the object they point to and must delete it

    4. D

      They guarantee that the object remains alive after its owner is destroyed

    Correct answer
    A

    They can refer to objects owned elsewhere rather than necessarily representing ownership themselves

    Explanation

    The lecture distinguishes ownership from reference: pointers and iterators can be used to refer to objects whose ownership belongs elsewhere.

  37. 37

    What is the core idea of moving a large object, such as a matrix, rather than copying it?

    1. A

      Transfer its representation to the destination instead of duplicating all of its elements

    2. B

      Convert the matrix into a pointer that has no owner

    3. C

      Keep two full copies but assign them the same name

    4. D

      Recalculate every element in the destination from the original inputs

    Correct answer
    A

    Transfer its representation to the destination instead of duplicating all of its elements

    Explanation

    The speaker describes moving as transferring the representation, such as a pointer to allocated storage, rather than copying all the matrix elements.

  38. 38

    Why can copying a large matrix to return it from a function be inefficient?

    1. A

      A copy always requires a separate garbage collector

    2. B

      A matrix cannot be represented as an object returned by a function

    3. C

      Copying changes the mathematical values of the matrix

    4. D

      The copy may duplicate a large number of elements even though the caller only needs the result

    Correct answer
    D

    The copy may duplicate a large number of elements even though the caller only needs the result

    Explanation

    The lecture uses large matrices to show why duplicating all their elements during a return can be costly.

  39. 39

    How can a move operation leave the source object safe to destroy?

    1. A

      It copies the resource and prevents the source destructor from running

    2. B

      It marks both objects as owners of the same resource without coordination

    3. C

      It delays both objects' destructors until the program terminates

    4. D

      It transfers the resource representation and leaves the source in a state that owns nothing to release

    Correct answer
    D

    It transfers the resource representation and leaves the source in a state that owns nothing to release

    Explanation

    In the lecture's example, the representation is transferred and the source is cleared, so its destructor has no resource left to release.

  40. 40

    What does a move constructor specify?

    1. A

      How an object is constructed by taking the resources or representation of another object

    2. B

      How a function sorts elements in a container

    3. C

      How an object must be copied element by element from every possible source

    4. D

      How a class selects which virtual function to call at runtime

    Correct answer
    A

    How an object is constructed by taking the resources or representation of another object

    Explanation

    The lecturer describes a move constructor as defining how an object's representation can be transferred from another object.

  41. 41

    How can a class avoid writing a custom move operation for every member?

    1. A

      By replacing its constructors with a garbage collector

    2. B

      By converting all of its members into raw pointers

    3. C

      By requiring every member to use shared ownership

    4. D

      If its members already know how to move, the language can generate suitable move behavior

    Correct answer
    D

    If its members already know how to move, the language can generate suitable move behavior

    Explanation

    The lecture explains that when a class is composed of members that already support copying and moving, generated operations can handle the members.

  42. 42

    Why can returning a matrix by value work efficiently when move semantics are available?

    1. A

      The result's representation can be transferred rather than copying every matrix element

    2. B

      A return statement skips the matrix destructor in all cases

    3. C

      Returning by value automatically changes the matrix into a reference

    4. D

      Move semantics make the matrix's elements unnecessary

    Correct answer
    A

    The result's representation can be transferred rather than copying every matrix element

    Explanation

    Move semantics make value returns practical for large objects by allowing their resources or representation to be transferred efficiently.

  43. 43

    Why does the lecturer object to forcing matrix operations to write into a caller-provided output object?

    1. A

      It prevents programs from using references to matrix elements

    2. B

      It makes it impossible to reuse a matrix in another operation

    3. C

      It guarantees that all intermediate matrices are copied

    4. D

      It makes natural value-based mathematical expressions less direct and can add setup complexity

    Correct answer
    D

    It makes natural value-based mathematical expressions less direct and can add setup complexity

    Explanation

    The speaker argues that requiring a pre-created output target for an operation such as matrix addition regresses from natural value-based mathematical code.

  44. 44

    What does the lecture say about compiler optimization and move operations?

    1. A

      Move operations work only if the compiler removes every constructor

    2. B

      Compiler optimization is required to make raw-pointer ownership safe

    3. C

      Compilers may optimize some copies, but explicit move support does not have to rely on such optimization

    4. D

      Compilers can never optimize a return of an object

    Correct answer
    C

    Compilers may optimize some copies, but explicit move support does not have to rely on such optimization

    Explanation

    The lecturer distinguishes compiler optimizations from move semantics: a compiler may eliminate copies, but moving provides a direct way to transfer resources.

  45. 45

    What is the lecturer's main criticism of relying on garbage collection for all resource management?

    1. A

      It primarily handles memory, while programs also manage resources such as files, locks, and connections

    2. B

      It cannot identify any memory that is no longer in use

    3. C

      It prevents programs from using containers

    4. D

      It requires every resource to be represented as a class hierarchy

    Correct answer
    A

    It primarily handles memory, while programs also manage resources such as files, locks, and connections

    Explanation

    The speaker argues that memory collection alone does not manage many other resource types that need explicit cleanup.

  46. 46

    Why does the lecturer compare some garbage-collection work to a shared resource?

    1. A

      Garbage collection makes each object exclusively owned by one thread

    2. B

      Collection can require coordination among program activity rather than being a cost-free local operation

    3. C

      Collection removes the need for any synchronization between threads

    4. D

      Garbage collection stores every object's resources in a separate process

    Correct answer
    B

    Collection can require coordination among program activity rather than being a cost-free local operation

    Explanation

    The lecture emphasizes that garbage collection can impose shared-system costs, particularly in concurrent programs.

  47. 47

    In the shape example, when is shared ownership more appropriate than unique ownership?

    1. A

      When multiple tasks genuinely need to keep the same object alive and no single task is its sole owner

    2. B

      When the program only needs to refer to an object without extending its lifetime

    3. C

      When a container owns each shape exclusively

    4. D

      When one function creates an object and uses it only within its own scope

    Correct answer
    A

    When multiple tasks genuinely need to keep the same object alive and no single task is its sole owner

    Explanation

    The lecture presents shared ownership as useful when several users, such as concurrent tasks, must jointly keep an object alive.

  48. 48

    What does the lecturer suggest as a possible way to handle legacy code that cannot readily be converted to modern resource-management practices?

    1. A

      Convert all legacy pointers into references without changing other code

    2. B

      Prevent the legacy program from allocating memory

    3. C

      Remove every destructor so that old cleanup code cannot conflict

    4. D

      Run a garbage collector infrequently to deal with accumulated memory garbage

    Correct answer
    D

    Run a garbage collector infrequently to deal with accumulated memory garbage

    Explanation

    The speaker mentions occasional or infrequent garbage collection as a possible approach for old code that is difficult to modernize.

  49. 49

    When is object-oriented inheritance especially useful, according to the lecture?

    1. A

      When a program must avoid all runtime function calls

    2. B

      When the concepts in a problem domain have meaningful hierarchical relationships

    3. C

      Whenever a function needs to return a value

    4. D

      Whenever a program contains any data structure

    Correct answer
    B

    When the concepts in a problem domain have meaningful hierarchical relationships

    Explanation

    The lecturer says inheritance fits domains with real hierarchies, using shapes and their more specific forms as an example.

  50. 50

    What is the purpose of a virtual function in the shape example?

    1. A

      It prevents derived classes from defining their own behavior

    2. B

      It copies each derived object into the base class

    3. C

      It makes every shape object a compile-time constant

    4. D

      It allows a call through a base-class interface to invoke behavior provided by a derived shape

    Correct answer
    D

    It allows a call through a base-class interface to invoke behavior provided by a derived shape

    Explanation

    The shape example uses virtual behavior so that different shapes can be drawn through a common interface.

  51. 51

    What does the lecture say about the runtime cost of virtual function calls?

    1. A

      They require garbage collection after every call

    2. B

      They are always more expensive than copying an entire object

    3. C

      They have some cost, though improvements such as branch prediction can reduce its practical impact

    4. D

      They have no runtime cost in any implementation

    Correct answer
    C

    They have some cost, though improvements such as branch prediction can reduce its practical impact

    Explanation

    The speaker describes virtual calls as relatively cheap but notes that they may still matter, especially when inlining is important.

  52. 52

    Why can virtual functions be a concern in high-performance code?

    1. A

      Virtual functions prevent programs from using constructors

    2. B

      Virtual functions require every object to be stored in a vector

    3. C

      Indirect calls always allocate memory for a new object

    4. D

      Indirect calls may make it harder for the compiler to inline a small operation

    Correct answer
    D

    Indirect calls may make it harder for the compiler to inline a small operation

    Explanation

    The lecturer identifies the difficulty of inlining virtual calls as a potential issue when the operation being dispatched is small and performance-sensitive.

  53. 53

    What is one problem the lecturer associates with very deep or large class hierarchies?

    1. A

      They remove the need to define interfaces

    2. B

      They make every operation statically dispatched

    3. C

      They can make code harder to understand and maintain when used without a suitable domain structure

    4. D

      They prevent objects from having different types

    Correct answer
    C

    They can make code harder to understand and maintain when used without a suitable domain structure

    Explanation

    The speaker cautions against treating enormous inheritance hierarchies as a definition of good programming.

  54. 54

    Why does the lecture warn programmers about using protected data?

    1. A

      It prevents derived classes from accessing any functions

    2. B

      It guarantees that data is cleaned up before the object is destroyed

    3. C

      It exposes representation to derived classes, making it harder to preserve a class's invariants

    4. D

      It makes all data public to every part of the program

    Correct answer
    C

    It exposes representation to derived classes, making it harder to preserve a class's invariants

    Explanation

    The lecturer warns that protected data lets derived classes modify representation, which can make invariants difficult to maintain.

  55. 55

    What does the lecture distinguish about inheritance in C++?

    1. A

      C++ supports implementation inheritance but not interfaces

    2. B

      C++ inheritance always copies a base class's implementation at runtime

    3. C

      C++ can provide both interface inheritance and implementation inheritance

    4. D

      C++ supports interface inheritance only through raw pointers

    Correct answer
    C

    C++ can provide both interface inheritance and implementation inheritance

    Explanation

    The speaker notes that C++ supports interface inheritance and also implementation inheritance.

  56. 56

    What is an abstract class in the lecture's description?

    1. A

      A class that does not provide a complete implementation and can define a required interface

    2. B

      A class that contains only data and cannot declare operations

    3. C

      A class that can be used only as a template argument

    4. D

      A class that automatically owns every object derived from it

    Correct answer
    A

    A class that does not provide a complete implementation and can define a required interface

    Explanation

    The lecturer describes abstract classes as classes without a full implementation that can provide an interface for derived classes.

  57. 57

    Which statement best reflects the lecture's view of programming paradigms?

    1. A

      Generic programming and object-oriented programming cannot appear in the same code

    2. B

      Object-oriented, generic, and other styles can be combined when they suit the problem

    3. C

      Using a newer paradigm makes all earlier styles obsolete

    4. D

      A program must use only one programming paradigm to be well designed

    Correct answer
    B

    Object-oriented, generic, and other styles can be combined when they suit the problem

    Explanation

    The lecturer argues against language or paradigm wars and gives examples that combine generic algorithms with object-oriented behavior.

  58. 58

    What is generic programming intended to make possible?

    1. A

      Replacing all data structures with class hierarchies

    2. B

      Writing an algorithm that can use only one fixed element type

    3. C

      Writing types and algorithms that can work with many suitable element or container types

    4. D

      Avoiding type checking by converting every value into a raw pointer

    Correct answer
    C

    Writing types and algorithms that can work with many suitable element or container types

    Explanation

    The lecture presents templates as a way to parameterize types and algorithms so they can work with different suitable types.

  59. 59

    Why did the lecturer want generic vectors and algorithms rather than versions fixed to one element type?

    1. A

      The same operations, such as sorting, should be usable for vectors of different element types

    2. B

      Each element type must use a different programming language

    3. C

      Fixed-type algorithms cannot be compiled

    4. D

      Generic algorithms prevent values from being compared

    Correct answer
    A

    The same operations, such as sorting, should be usable for vectors of different element types

    Explanation

    The speaker wanted a vector and operations such as sorting to be parameterized by the element type rather than tied to one fixed type.

  60. 60

    What is 'duck typing' as described in the lecture?

    1. A

      Using a type according to whether it supports the operations the code attempts to perform

    2. B

      Selecting a type only by its name in a class hierarchy

    3. C

      Converting every argument to the same built-in type before a function call

    4. D

      Checking whether a value has been allocated by a garbage collector

    Correct answer
    A

    Using a type according to whether it supports the operations the code attempts to perform

    Explanation

    The lecture describes duck typing as relying on whether a type supports the operations used by the generic code.

  61. 61

    What is a major drawback of relying only on template errors to reveal that an argument type is unsuitable?

    1. A

      The program always runs successfully despite the unsuitable type

    2. B

      The resulting compiler diagnostics can be extremely long and difficult to connect to the actual problem

    3. C

      The compiler cannot detect template errors until the program is running

    4. D

      The compiler automatically changes the argument type to a suitable one

    Correct answer
    B

    The resulting compiler diagnostics can be extremely long and difficult to connect to the actual problem

    Explanation

    The speaker emphasizes that template errors may be detected during compilation but can produce very confusing diagnostics.

  62. 62

    Why do programmers sometimes perform computations at compile time?

    1. A

      Compile-time work guarantees that a program needs no runtime data

    2. B

      It allows errors to be hidden until after a program is shipped

    3. C

      It makes every template independent of its argument types

    4. D

      It can improve performance or express work at the earliest stage when it can be checked

    Correct answer
    D

    It can improve performance or express work at the earliest stage when it can be checked

    Explanation

    The lecture gives performance and early expression or checking of work as reasons programmers use compile-time computation.

  63. 63

    What is a concept intended to express for a template?

    1. A

      The runtime order in which a program's functions must be called

    2. B

      The requirements that the template places on its type arguments

    3. C

      The exact memory address where every template object must be stored

    4. D

      The number of copies the compiler must make for every template argument

    Correct answer
    B

    The requirements that the template places on its type arguments

    Explanation

    The lecturer describes concepts as a way to state the intended requirements of a template's arguments.

  64. 64

    Why would a list of integers fail to meet the lecture's stated requirements for a sorting algorithm that needs random access?

    1. A

      A list cannot be traversed from beginning to end

    2. B

      A list does not support direct random access to its elements in the way the algorithm requires

    3. C

      A list has no elements that can be compared

    4. D

      A list cannot contain integers

    Correct answer
    B

    A list does not support direct random access to its elements in the way the algorithm requires

    Explanation

    The lecture explains that the sorting requirements include random access; a list does not provide that capability, so it does not satisfy the constraint.

  65. 65

    How can concepts improve a template error message?

    1. A

      They prevent templates from being used with containers

    2. B

      They replace compile-time checking with runtime warnings

    3. C

      They can report directly that an argument type fails a stated requirement

    4. D

      They silently convert an unsuitable type into a suitable type

    Correct answer
    C

    They can report directly that an argument type fails a stated requirement

    Explanation

    The lecturer contrasts concept-based diagnostics, which identify an unmet requirement, with the confusing errors common in unconstrained templates.

  66. 66

    What is the role of a predicate in the lecture's sorting example?

    1. A

      It transfers a container's resources to another container

    2. B

      It specifies how two elements should be ordered or compared

    3. C

      It determines how many elements the container can hold

    4. D

      It records which function owns the container's memory

    Correct answer
    B

    It specifies how two elements should be ordered or compared

    Explanation

    The lecture uses predicates to provide comparison criteria for algorithms such as sorting or finding elements.

  67. 67

    What does a lambda expression provide in the lecture's example?

    1. A

      A declaration that an element type has random access

    2. B

      A way to make every function call virtual

    3. C

      A concise way to supply an operation or predicate directly to an algorithm

    4. D

      A method for transferring ownership of a container

    Correct answer
    C

    A concise way to supply an operation or predicate directly to an algorithm

    Explanation

    The speaker shows a lambda as a compact way to write a comparison operation passed to an algorithm.

  68. 68

    Why are algorithms often expressed using a beginning and ending iterator rather than assuming the whole container?

    1. A

      The same algorithm can then operate on either a full sequence or a selected portion

    2. B

      Iterators automatically determine the container's ownership

    3. C

      A full container cannot be sorted directly

    4. D

      The algorithm can then avoid knowing what operations its elements support

    Correct answer
    A

    The same algorithm can then operate on either a full sequence or a selected portion

    Explanation

    The lecture explains that iterator ranges allow algorithms to work on subsequences as well as entire sequences.

  69. 69

    What does the lecture say about combining generic programming with object-oriented programming?

    1. A

      Using a template removes the runtime behavior of class hierarchies

    2. B

      A generic algorithm can operate on containers whose elements use object-oriented interfaces

    3. C

      Object-oriented types cannot be stored in generic containers

    4. D

      Generic algorithms cannot call virtual functions

    Correct answer
    B

    A generic algorithm can operate on containers whose elements use object-oriented interfaces

    Explanation

    The speaker demonstrates generic iteration over a container of shapes while using object-oriented drawing behavior.

  70. 70

    Why does the lecturer describe generic programming as ordinary programming rather than a completely separate discipline?

    1. A

      Generic code is executed only by a separate programming language

    2. B

      The same basic ideas of functions, types, and operations still apply, though templates add complexity

    3. C

      Templates do not use types or functions

    4. D

      Every generic program must be written as a class hierarchy

    Correct answer
    B

    The same basic ideas of functions, types, and operations still apply, though templates add complexity

    Explanation

    The lecturer argues that generic programming uses familiar programming ideas and should not require an entirely different way of reasoning.

  71. 71

    What role can containers such as vectors and maps play in reducing memory-safety problems?

    1. A

      They remove the need to know what data a program stores

    2. B

      They guarantee that no program can contain a logic error

    3. C

      They make all element access valid regardless of index

    4. D

      They can manage storage and expose useful operations without requiring direct manipulation of raw arrays

    Correct answer
    D

    They can manage storage and expose useful operations without requiring direct manipulation of raw arrays

    Explanation

    The lecture recommends standard containers as a way to manage data and avoid many hazards associated with direct array and pointer use.

  72. 72

    Why does the lecturer connect direct use of C-style arrays with buffer-overflow risks?

    1. A

      Arrays prevent a program from checking an index

    2. B

      Array elements are always allocated by a garbage collector

    3. C

      Array sizes can be lost or overlooked, making out-of-range access easier

    4. D

      Arrays cannot store more than one element

    Correct answer
    C

    Array sizes can be lost or overlooked, making out-of-range access easier

    Explanation

    The speaker explains that C-style arrays can lose their size information, making it easier to access memory outside their bounds.

  73. 73

    What is the lecturer's response to blaming early C designers for every later security flaw?

    1. A

      Modern containers cannot reduce the risks of older programming styles

    2. B

      Early language designers should be blamed whenever a program uses a pointer

    3. C

      The language designers deserve credit for raising programming abstraction, while later programmers should also be responsible for using safer practices

    4. D

      All security flaws are unavoidable consequences of using a compiled language

    Correct answer
    C

    The language designers deserve credit for raising programming abstraction, while later programmers should also be responsible for using safer practices

    Explanation

    The lecturer defends the historical contribution of C's designers and argues that continuing to write unsafe old-style code is also a source of responsibility.

  74. 74

    What future safety improvement does the lecturer anticipate from hardware range checking?

    1. A

      Hardware support could detect or enforce bounds on accesses that would otherwise be out of range

    2. B

      Range checking could make all pointer ownership unambiguous

    3. C

      Hardware could guarantee that every program is free of logic errors

    4. D

      Hardware support could eliminate the need for type checking

    Correct answer
    A

    Hardware support could detect or enforce bounds on accesses that would otherwise be out of range

    Explanation

    The speaker anticipates hardware support for range checking to help enforce safety against out-of-bounds accesses.

  75. 75

    Why does the lecturer consider static analysis valuable for large C++ codebases?

    1. A

      It can help identify problems and support understanding of complex existing code

    2. B

      It guarantees that all legacy code is compatible with every compiler

    3. C

      It removes the need for developers to read code

    4. D

      It automatically rewrites every program into a new language

    Correct answer
    A

    It can help identify problems and support understanding of complex existing code

    Explanation

    The lecture points to static analysis tools as a way to find problems and help developers understand large codebases.

  76. 76

    How might code transformation help organizations maintain old C++ systems?

    1. A

      It replaces the need to preserve behavior during upgrades

    2. B

      It can guarantee that a program needs no testing after transformation

    3. C

      It can make old code compatible with every compiler automatically

    4. D

      It could help modernize or simplify existing code without requiring every change to be made manually

    Correct answer
    D

    It could help modernize or simplify existing code without requiring every change to be made manually

    Explanation

    The speaker expresses hope that analysis and transformation tools can help rejuvenate or modernize existing code.

  77. 77

    Why can repeated inclusion of the same header files increase compilation time?

    1. A

      Each inclusion creates a separate copy of every runtime object

    2. B

      The compiler may have to process the header contents repeatedly across many source files

    3. C

      Repeated headers prevent the compiler from checking types

    4. D

      Header files force the program to run its functions during compilation

    Correct answer
    B

    The compiler may have to process the header contents repeatedly across many source files

    Explanation

    The lecture identifies repeated processing of headers across source files as one contributor to long compilation times.

  78. 78

    How could a modules system reduce some compilation costs?

    1. A

      It could eliminate the need to compile source code

    2. B

      It could prevent programs from using libraries

    3. C

      It could make every function execute at compile time

    4. D

      It could avoid repeatedly processing the same interface information in many source files

    Correct answer
    D

    It could avoid repeatedly processing the same interface information in many source files

    Explanation

    The speaker describes modules as a possible way to reduce redundant processing of headers and related information.

  79. 79

    Why can programs compiled by different C++ compilers have difficulty linking together?

    1. A

      C++ does not have one universally followed binary linkage and object-format convention across compilers

    2. B

      C++ programs cannot use code compiled in earlier language versions

    3. C

      C++ forbids programs from using more than one source file

    4. D

      Different compilers always assign different meanings to every class

    Correct answer
    A

    C++ does not have one universally followed binary linkage and object-format convention across compilers

    Explanation

    The lecture describes binary compatibility and linking across compilers as a real problem because linkage conventions have not been standardized in a way that ensures universal interoperability.

  80. 80

    Why do compiler vendors often prioritize compatibility with their own previous compiler versions?

    1. A

      Compatibility with earlier versions makes new features impossible

    2. B

      Customers generally require every release to break existing code

    3. C

      A compiler can link only to programs written in the same year

    4. D

      Their customers may have large codebases built with those versions

    Correct answer
    D

    Their customers may have large codebases built with those versions

    Explanation

    The speaker observes that vendors have strong incentives to preserve compatibility with the code their existing customers already use.

  81. 81

    Why can adoption of a newer C++ standard be slow in some organizations?

    1. A

      Large codebases may need to remain buildable with older compilers or across fragmented teams

    2. B

      New features require every program to abandon its existing algorithms

    3. C

      Modern code cannot be compiled by any commercial compiler

    4. D

      Newer standards cannot support production software

    Correct answer
    A

    Large codebases may need to remain buildable with older compilers or across fragmented teams

    Explanation

    The lecture notes that organizations with large codebases or many separate user groups may be constrained by older compilers and inconsistent development practices.

  82. 82

    What benefits does the lecturer say can help persuade organizations to adopt modern C++ styles?

    1. A

      They eliminate the need for compatibility with existing systems

    2. B

      They make all programs shorter, regardless of their purpose

    3. C

      They guarantee that developers will not need to learn new tools

    4. D

      They can improve safety and may produce faster code

    Correct answer
    D

    They can improve safety and may produce faster code

    Explanation

    The speaker argues that modern styles should be promoted by demonstrating their safety and performance benefits.

  83. 83

    Why does the lecturer reject the idea that C++ should simply be replaced by Java for systems programming?

    1. A

      The lecturer considers Java's garbage collection and virtual-machine model unsuitable for some desired systems-programming goals

    2. B

      Java cannot be used to build any large software system

    3. C

      C++ and Java have identical designs and therefore cannot be compared

    4. D

      Java does not support object-oriented programming

    Correct answer
    A

    The lecturer considers Java's garbage collection and virtual-machine model unsuitable for some desired systems-programming goals

    Explanation

    The lecturer argues that Java's design choices, including garbage collection and a virtual machine, conflict with some of the systems-programming properties desired for C++.

  84. 84

    What is the lecturer's overall position on improving C++?

    1. A

      Remove all historical features immediately, regardless of compatibility

    2. B

      Replace abstractions with direct hardware operations in every program

    3. C

      Make the language specialized for one application domain

    4. D

      Improve the language while preserving its ability to support low-level work, performance, and existing code

    Correct answer
    D

    Improve the language while preserving its ability to support low-level work, performance, and existing code

    Explanation

    The lecturer frames improvement as a balance: C++ should become better while respecting compatibility and its role in both low-level and abstract programming.

Question 1 of 84
Question 1 of 84

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent