1. Home
  2. Explore
  3. Computer Science
  4. CS50 Debugging Tools

Study methods

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

CS50 Debugging Tools

  • 85Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Debugging Tools
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What does debug50 allow a programmer to do?

Tap to flipClick to flipspace

Step through code line by line, inspect variables, and use breakpoints to investigate program behavior.

Or swipe the card

85 cards

  1. What does debug50 allow a programmer to do?

    Step through code line by line, inspect variables, and use breakpoints to investigate program behavior.

  2. What is the purpose of check50?

    To automatically run tests that check whether a program produces the expected results.

  3. When is printf useful for debugging?

    It can display variable values, confirm that execution reached a particular point, or show when a loop is running.

  4. What does style50 check?

    The formatting and readability of C code, including spacing and indentation.

  5. When should a programmer use help50?

    When they do not understand a compiler or command-line error message.

  6. What problem does Valgrind primarily help detect?

    Invalid memory accesses and memory leaks.

  7. What does Valgrind mean by an invalid read or invalid write?

    The program accessed memory it was not allowed to read or modify, such as memory beyond an array's bounds.

  8. How can help50 make Valgrind output easier to understand?

    It interprets Valgrind's technical messages and points to likely source-code lines and causes.

  9. What does Valgrind report when allocated memory is never released?

    It reports that memory is definitely lost, indicating a memory leak.

  10. What is rubber duck debugging?

    Explaining code aloud, step by step, to an inanimate object or another listener in order to reveal logical mistakes.

  11. What command-line arguments should be supplied when running Valgrind?

    The same arguments normally supplied to the program, with Valgrind placed before the command.

  12. Why should programmers use debugging tools instead of relying only on visual inspection?

    Tools provide additional evidence about execution, memory use, and errors that may not be visible from the source code or output.

  13. What does malloc do?

    It requests a dynamically allocated block of memory from the heap and returns its address.

  14. What type of value does malloc return?

    A pointer containing the address of the allocated memory block.

  15. Why should sizeof be used when allocating space for integers?

    It determines the platform-specific size of an integer instead of assuming a fixed number of bytes.

  16. Why can dynamically allocated memory be accessed using array notation?

    A block returned by malloc is contiguous, so its elements can be accessed by index like an array.

  17. What is an out-of-bounds access?

    Reading or writing beyond the valid indexes of an array or allocated memory block.

  18. Why might an out-of-bounds access appear to work in C?

    The program may accidentally access memory that happens to be available, even though it does not belong to the array.

  19. Why are bugs that work on one computer but fail on another especially difficult?

    They often depend on accidental memory layouts or other system-specific conditions.

  20. What does free do?

    It returns dynamically allocated memory to the operating system's pool of available memory.

  21. What is a memory leak?

    Allocated memory that a program no longer uses but has failed to release.

  22. When should allocated memory generally be freed?

    After the program has finished using it, often near the end of the relevant computation or program.

  23. Why is using memory after calling free invalid?

    The memory has been returned to the operating system and is no longer guaranteed to belong to the program.

  24. What does NULL represent in pointer contexts?

    A special value indicating that a pointer does not refer to a valid memory location.

  25. What is a garbage value?

    An unpredictable bit pattern already present in memory that has not been initialized by the current program.

  26. Why should an uninitialized pointer never be dereferenced?

    It may contain an invalid or unpredictable address, so dereferencing it can access arbitrary memory or crash.

  27. What does dereferencing a pointer mean?

    Following the address stored in the pointer to access the data located there.

  28. What is stored in a pointer?

    The address of another object in memory.

  29. What is the text segment of a running program's memory?

    The region containing the program's machine code.

  30. What is stored in the heap?

    Dynamically allocated memory requested with functions such as malloc.

  31. What is stored in the stack?

    Function call frames and local variables.

  32. Why are programs loaded into RAM when they run?

    RAM is much faster for execution than long-term storage devices such as hard drives or solid-state drives.

  33. What can happen if the heap and stack grow into each other's space?

    The program may run out of usable memory and experience an overflow or other failure.

  34. Why did passing ordinary variables to the original swap function fail to swap the variables in main?

    The function received copies of the values, so it changed only its local copies.

  35. How can a function modify variables belonging to its caller?

    Pass pointers to the variables and dereference those pointers inside the function.

  36. What role does a temporary variable play in swapping two values?

    It temporarily stores one value so it is not overwritten while the other value is moved into its place.

  37. What is a struct in C?

    A programmer-defined data type that groups related fields, possibly of different types.

  38. What does typedef allow a programmer to do with a structure?

    Give the structure a convenient type name.

  39. What is encapsulation in the context of structures?

    Grouping related data into one data structure instead of managing separate, corresponding variables or arrays.

  40. How are fields of a structure accessed when using a structure variable directly?

    With the dot operator, such as student.name.

  41. Why did the linked-list node declaration mention struct node before defining all its fields?

    The self-referential pointer needs the compiler to know that the structure type exists before the pointer field is declared.

  42. What is a major limitation of a conventional C array?

    Its capacity is fixed when the array is allocated.

  43. What other limitation do conventional arrays have concerning element types?

    All elements normally must have the same data type.

  44. What is the time complexity of expanding an array by allocating a new array and copying all existing elements?

    O(n)O(n)O(n), where nnn is the number of existing elements.

  45. What does realloc do?

    It changes the size of an existing dynamically allocated memory block and returns the address of the resized block.

  46. Why can realloc still require linear time?

    It may need to create a new block and copy all existing data into it.

  47. Why should the return value of realloc be stored in a temporary pointer first?

    If realloc fails and returns NULL, directly assigning it to the original pointer can lose the only reference to the old block.

  48. What is the difference between an array's size and its capacity?

    Size is the number of elements currently stored; capacity is the number of elements the allocated space can hold.

  49. Why might a program allocate more capacity than it currently needs?

    To reduce the number of future reallocations and improve performance.

  50. What trade-off is involved in overallocating an array?

    It can make insertion faster but wastes memory that is not currently being used.

  51. Why cannot getInt directly support a user typing q to stop input?

    getInt expects an integer and immediately handles the input as an integer request.

  52. What does pressing Control-D represent in the described input process?

    An end-of-file signal indicating that the user has finished providing input.

  53. What is a sentinel value?

    A special value reserved to signal a condition such as the end of input.

  54. Why should dynamically allocated arrays be freed after use?

    To prevent memory leaks.

  55. What is the basic structure of a linked-list node?

    A data value and a pointer to the next node.

  56. How does a linked list differ from an array in memory layout?

    Linked-list nodes need not be adjacent; pointers connect nodes that may be located anywhere in memory.

  57. What does the next pointer of the final linked-list node contain?

    NULL.

  58. What pointer must be retained to access an entire linked list?

    A pointer to the first node, often called the head or first pointer.

  59. Why is losing the first-node pointer a serious error?

    The rest of the linked list becomes inaccessible even if its nodes still exist in memory.

  60. What is the time complexity of inserting into a sorted linked list in the worst case?

    O(n)O(n)O(n).

  61. Why must a new node point to the successor before the predecessor is updated during insertion?

    Otherwise, updating the predecessor first can disconnect the rest of the list.

  62. What is the time complexity of inserting at the beginning of an unsorted linked list?

    O(1)O(1)O(1).

  63. What is a trade-off between sorted and unsorted linked lists?

    Sorted lists make ordered traversal easier but may require O(n)O(n)O(n) insertion; unsorted lists can insert at the front in O(1)O(1)O(1) time.

  64. How could a linked list support constant-time insertion at the end?

    Maintain a separate pointer to the last node.

  65. What is a doubly linked list?

    A linked list in which each node stores pointers to both the next and previous nodes.

  66. What does the arrow operator, ->, mean when used with a pointer to a structure?

    Follow the pointer and access a field of the pointed-to structure.

  67. What does a traversal loop that updates ptr to ptr->next accomplish?

    It moves through the linked list one node at a time.

  68. What is a hash function?

    A function that maps an input, such as a name, to an index or bucket.

  69. What is a hash table?

    A data structure that uses an array of buckets, often containing linked lists, to organize data by a hash function.

  70. Why combine an array with linked lists in a hash table?

    The array provides fast bucket access, while linked lists allow each bucket to grow dynamically.

  71. What is the worst-case lookup time for a hash table?

    O(n)O(n)O(n).

  72. What causes collisions in a hash table?

    Different inputs producing the same hash index.

  73. What property should a good hash function aim for?

    A relatively even distribution of items across buckets.

  74. What information could be used as input to a hash function for people?

    A first name, last name, identification number, or birth date.

  75. What is a binary search tree?

    A tree in which each node's left descendants contain smaller values and its right descendants contain larger values.

  76. What is the root of a tree?

    The topmost node and the starting point for traversing the tree.

  77. How many child pointers does a binary tree node typically contain?

    Two: one to a left child and one to a right child.

  78. What is the search time in a balanced binary search tree?

    O(log⁡n)O(\log n)O(logn).

  79. What can happen to binary-search-tree performance if the tree becomes severely unbalanced?

    Search can degrade to O(n)O(n)O(n).

  80. What is a trie?

    A tree-based structure used for retrieval in which each node contains an array of pointers to possible next characters.

  81. How is a word such as BILLY represented in a trie?

    By following one character-indexed pointer for each successive letter: B, then I, then L, then L, then Y.

  82. What is the lookup time for a word in a trie?

    O(k)O(k)O(k), where kkk is the word's length; for a fixed maximum word length, this is treated as O(1)O(1)O(1).

  83. What is the main cost of a trie?

    High memory usage.

  84. How can a trie distinguish between a complete word and a prefix of a longer word?

    Each node needs information indicating whether a complete word ends there or whether the path continues.

  85. Why are tries useful for spell checkers?

    They can determine quickly whether a typed word appears in a large dictionary.

Card 1 of 85
Card 1 of 85

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent