1. Home
  2. Explore
  3. Computer Science
  4. Image Filters in C

Study methods

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

Image Filters in C

  • 101Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Structures Files
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is a struct in C?

Tap to flipClick to flipspace

A user-defined data type that groups related fields, potentially of different types, into one structure.

Or swipe the card

101 cards

  1. What is a struct in C?

    A user-defined data type that groups related fields, potentially of different types, into one structure.

  2. How is a student structure defined if each student has a name and dorm?

    Using typedef struct { string name; string dorm; } student;.

  3. Why are structures often declared in .h header files?

    To make the structure definition available to multiple source files, similar to a shared library declaration.

  4. How does an array of structures store user information?

    After obtaining the desired number of elements, the program declares an array such as student students[enrollment].

  5. What does the dot operator do when accessing a structure?

    It accesses a particular field inside a structure, such as students[i].name or students[i].dorm.

  6. How does fopen open a file for writing?

    By passing the filename and the mode string "w", such as fopen("students.csv", "w").

  7. What does a variable of type FILE * represent?

    A pointer-like handle referring to an opened file.

  8. How can a program check whether fopen succeeded?

    Check whether the returned FILE * is not NULL.

  9. How does fprintf differ from printf?

    fprintf takes a file handle as its first argument and writes formatted output to that file instead of automatically writing to the screen.

  10. Why is fclose important after writing to a file?

    It closes the file and ensures that the written data is finalized and saved.

  11. What is a CSV file?

    A comma-separated values file in which rows and fields are represented as text separated by commas.

  12. Why do CSV files become inefficient for large-scale searching?

    Searching increasingly large CSV files becomes slower, motivating the use of databases.

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

    The region containing the compiled machine instructions of the program.

  14. Where are initialized and uninitialized global variables stored?

    They are stored in separate memory regions commonly called initialized data and uninitialized data.

  15. What are environment variables used for?

    They store values such as usernames, passwords, or configuration data outside the program's source code.

  16. What is the stack used for during function calls?

    It stores function call frames containing local variables, parameters, and related temporary information.

  17. What happens to a function's stack frame when the function returns?

    Its memory is considered available for reuse by later function calls.

  18. Why do uninitialized variables contain garbage values?

    They may contain leftover bits from earlier uses of the same memory region.

  19. What is the heap used for?

    It provides dynamically allocated memory that can remain available beyond the lifetime of a particular function call.

  20. Why cannot a function safely return the address of a local array?

    The array is stored in the function's stack frame, which becomes invalid for continued use when the function returns.

  21. Where does dynamically allocated memory from malloc come from?

    The heap.

  22. What is a pointer?

    A variable that stores the memory address of another value.

  23. What does int *p declare?

    A variable p that can store the address of an int.

  24. What does the unary * operator do when used with a pointer expression?

    It dereferences the pointer, accessing the value stored at the pointed-to address.

  25. What is the difference between p and *p?

    p is the address stored in the pointer; *p is the value located at that address.

  26. Why did passing ordinary integers to swap fail to change the caller's variables?

    The function received copies of the values in its own stack frame, so changing its local parameters did not change the caller's variables.

  27. How do pointers allow swap to modify the caller's variables?

    The caller passes the variables' addresses, allowing swap to dereference those addresses and modify the original values.

  28. What does malloc do?

    It allocates a requested number of bytes on the heap and returns the address of the allocated memory.

  29. Why is int *x; *x = 42; unsafe?

    The pointer x has not been given a valid allocated address, so dereferencing it accesses an unknown memory location.

  30. What is a segmentation fault?

    An error caused by accessing a memory region that the program is not allowed to access.

  31. What happens when y = x for two integer pointers?

    Both pointers store the same address and therefore point to the same memory location.

  32. What is the difference between assigning y = x and assigning *y = *x?

    y = x copies the address, whereas *y = *x copies the value stored at the pointed-to address.

  33. Can a C function directly return multiple values?

    No. A C function directly returns only one value, though pointers or structures can be used to provide multiple results indirectly.

  34. What is a memory leak?

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

  35. What does free do?

    It releases heap memory previously allocated by functions such as malloc.

  36. How does calloc differ from malloc?

    calloc allocates memory and initializes all allocated bytes to zero, whereas malloc leaves the contents uninitialized.

  37. What does realloc do?

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

  38. What happens if realloc receives NULL?

    It behaves similarly to allocating a new block of memory.

  39. What is a buffer?

    A region or chunk of memory used to store data.

  40. What is a buffer overflow?

    Writing more data into a buffer than the buffer has space to hold.

  41. Why is copying a 13-byte string into a 12-byte array unsafe?

    The thirteenth byte is written outside the array's valid bounds.

  42. How can a buffer overflow become a security exploit?

    An attacker may overwrite a stored return address with data that redirects execution to attacker-provided machine code.

  43. What is a return address on the stack?

    An address indicating where execution should resume after a called function finishes.

  44. What causes stack overflow?

    Excessive function calls or recursion that consume stack memory until the stack reaches memory it should not overwrite.

  45. What causes heap overflow?

    Allocating or writing beyond the available heap memory, potentially causing the heap to grow into the stack or corrupt nearby memory.

  46. What is Valgrind used for?

    Detecting memory-related errors such as invalid memory access and memory leaks.

  47. What does Valgrind's message invalid write of size 4 typically mean?

    The program attempted to write four bytes to an invalid memory location, often by writing an int outside an allocated region.

  48. What does a Valgrind report that bytes are definitely lost indicate?

    The program allocated memory but lost the pointer to it without freeing the memory.

  49. What does hexadecimal notation commonly represent in debugging output?

    Memory addresses or other numeric values.

  50. What is rubber-duck debugging?

    Explaining code aloud to an object or listener in order to clarify the program's behavior and reveal mistakes.

  51. Why is an ordinary fixed-size array difficult to grow?

    Its elements occupy one contiguous memory block, so increasing its size may require allocating a new block and copying all existing elements.

  52. What is the time complexity of copying an array of nnn elements into a larger array?

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

  53. Why can memory fragmentation prevent allocation of a large array?

    There may be enough total free memory, but not enough free memory in one contiguous block.

  54. What is a linked list?

    A sequence of nodes connected by pointers, where each node stores data and a pointer to another node.

  55. What fields does a typical singly linked-list node contain?

    A data value and a pointer called next to the next node.

  56. How is the beginning of a linked list represented?

    By a separate pointer, often called first or head, that stores the address of the first node.

  57. What does a NULL next pointer indicate in a linked list?

    That the node is the final node in the list.

  58. What is the main advantage of a linked list over a fixed-size array?

    It can grow or shrink dynamically without requiring the entire collection to be copied.

  59. What is a major cost of linked lists?

    They use extra memory for pointers and require more complex code than arrays.

  60. Why does a linked list not support ordinary array indexing?

    Its nodes may be scattered throughout memory, so reaching a position requires following pointers from the beginning.

  61. What is the time complexity of searching a linked list?

    O(n)O(n)O(n) in the worst case.

  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 the time complexity of inserting into a sorted linked list?

    O(n)O(n)O(n) in general because the correct position may require traversing the list.

  64. What pointer updates are needed to insert a node into the middle of a linked list?

    The new node points to the former successor, and the predecessor's next pointer is changed to point to the new node.

  65. How can an entire linked list be freed safely?

    Save the current node's next pointer, free the current node, and then advance to the saved next pointer until reaching NULL.

  66. What does the arrow operator -> do in C?

    It accesses a structure member through a pointer to that structure.

  67. What is the difference between . and -> for structures?

    Use . with a structure value and -> with a pointer to a structure.

  68. What is a stack as an abstract data structure?

    A last-in, first-out (LIFO) structure supporting operations commonly called push and pop.

  69. What does LIFO mean?

    Last in, first out: the most recently added item is removed first.

  70. How can a stack be implemented with an array?

    Store the elements in an array and track the current size and maximum capacity.

  71. What is the main limitation of a fixed-size array implementation of a stack?

    It cannot store more elements than its predetermined capacity.

  72. What is a queue as an abstract data structure?

    A first-in, first-out (FIFO) structure in which the earliest added item is removed first.

  73. What does FIFO mean?

    First in, first out: the earliest added item is removed first.

  74. Why should a queue track a front position when implemented with an array?

    To identify the next item to remove without shifting every remaining element forward.

  75. What is an API?

    An application programming interface: a defined set of operations and behaviors that a data structure or program exposes to users.

  76. What is abstraction in data-structure design?

    Separating the behavior and interface of a structure from the details of how it is implemented.

  77. What is technical debt?

    The future cost created by choosing quick or poorly designed solutions instead of addressing design and correctness issues immediately.

  78. What is a tree data structure?

    A set of nodes connected hierarchically, in which nodes may have children and descendants.

  79. What is the root of a tree?

    The topmost node from which the tree's descendants originate.

  80. What is a leaf in a tree?

    A node with no children.

  81. What is a binary tree?

    A tree in which each node has at most two children.

  82. What is a binary search tree?

    A binary tree in which each node's left subtree contains smaller values and its right subtree contains larger values.

  83. How are child pointers represented for a leaf in a binary search tree?

    Both the left and right pointers are NULL.

  84. What is the search time for a balanced binary search tree?

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

  85. What happens to a binary search tree's performance if it becomes highly unbalanced?

    It can degrade to O(n)O(n)O(n), behaving similarly to a linked list.

  86. How does recursive search in a binary search tree work?

    Return false for a NULL tree; search left if the target is smaller, search right if larger, and return true if equal to the current node.

  87. Why is a subtree still considered a tree?

    It has the same recursive structure: a root node with zero or more child subtrees.

  88. What is hashing?

    Using a function to map an input value to a bucket or index.

  89. What is a hash function?

    A function that examines an input and produces a hash value used to choose a bucket.

  90. What is a hash table?

    A data structure that uses an array of buckets and a hash function to locate stored values.

  91. What is a hash collision?

    When two different inputs produce the same hash value or bucket.

  92. What is linear probing?

    A collision-resolution method that searches sequentially for the next available array position.

  93. What is separate chaining?

    A collision-resolution method in which each hash-table bucket points to a linked list of values.

  94. Why should a hash function distribute values uniformly?

    To keep the chains approximately equal in length and make lookup efficient.

  95. What is the practical benefit of dividing data among hash-table buckets?

    A lookup examines only the relevant bucket rather than the entire data set.

  96. What is a trie?

    A tree-like data structure that stores strings by following one pointer per character.

  97. How is a word such as Maxwell stored in a trie?

    The structure follows pointers selected by M, then a, then x, then w, e, l, and l, ending at a marker indicating a complete word.

  98. What does an end-of-word marker represent in a trie?

    It indicates that the character sequence ending at that node forms a complete stored word.

  99. What determines the lookup time for a word in a trie?

    The number of characters in the word, not the total number of words stored.

  100. What is the theoretical lookup complexity of a trie when word length is treated as bounded?

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

  101. What is the main trade-off of a trie?

    It provides very fast lookup but consumes more memory because each node may contain many child pointers.

Card 1 of 101
Card 1 of 101

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent