-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc07_quiz.json
More file actions
85 lines (85 loc) · 17.6 KB
/
Copy pathc07_quiz.json
File metadata and controls
85 lines (85 loc) · 17.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
[
{ q: 'What does ft_strdup return if the call to malloc fails?', options: ['NULL', '0', 'An empty string', 'Undefined behavior'], answer: 'NULL' },
{ q: 'What is the correct prototype of ft_strdup?', options: ['char *ft_strdup(char *src)', 'char *ft_strdup(char src)', 'int ft_strdup(char *src)', 'void *ft_strdup(char *src)'], answer: 'char *ft_strdup(char *src)' },
{ q: 'How many bytes does ft_strdup allocate for duplicating the string "42"?', options: ['2', '3', '4', 'Depends on the implementation'], answer: '3' },
{ q: 'Which standard C library function does ft_strdup mimic?', options: ['strcpy', 'strdup', 'strncpy', 'memcpy'], answer: 'strdup' },
{ q: 'In ft_strdup, the size passed to malloc must include space for which character?', options: ['The first character', 'The null terminator', 'A newline', 'The last character'], answer: 'The null terminator' },
{ q: 'What should ft_strdup do if the source string src is NULL?', options: ['Return NULL', 'Return an empty string', 'Cause a segmentation fault', 'Undefined behavior'], answer: 'Undefined behavior' },
{ q: 'Which header file is required for using malloc in ft_strdup?', options: ['<string.h>', '<stdlib.h>', '<stdio.h>', '<unistd.h>'], answer: '<stdlib.h>' },
{ q: 'After ft_strdup successfully returns, who is responsible for freeing the allocated memory?', options: ['The caller', 'The ft_strdup function', 'The operating system', 'The kernel'], answer: 'The caller' },
{ q: 'What does ft_range return when min is greater than or equal to max?', options: ['NULL', '0', 'An empty array', 'A pointer to an empty array'], answer: 'NULL' },
{ q: 'ft_range creates an array of integers from min to what upper bound?', options: ['max', 'max - 1', 'max + 1', 'max / 2'], answer: 'max - 1' },
{ q: 'How many integers are allocated by ft_range(3, 8)?', options: ['5', '8', '3', '11'], answer: '5' },
{ q: 'What is the return type of ft_range?', options: ['int *', 'int', 'void *', 'int **'], answer: 'int *' },
{ q: 'If ft_range(5, 5) is called, what is returned?', options: ['An array containing 5', 'NULL', 'An empty array', 'An array with one element'], answer: 'NULL' },
{ q: 'What is the last element of the array returned by ft_range(1, 5)?', options: ['5', '4', '1', '0'], answer: '4' },
{ q: 'How much memory does ft_range(0, 10) allocate on a system where sizeof(int) is 4?', options: ['10 bytes', '40 bytes', '80 bytes', '20 bytes'], answer: '40 bytes' },
{ q: 'What is the first element of the array returned by ft_range(-3, 2)?', options: ['-3', '-2', '0', '2'], answer: '-3' },
{ q: 'What does ft_ultimate_range return when the allocation is successful?', options: ['The size of the array', 'A pointer to the array', '0', '1'], answer: 'The size of the array' },
{ q: 'What does ft_ultimate_range set *range to when min >= max?', options: ['NULL', 'A valid pointer', '0', 'The address of a local variable'], answer: 'NULL' },
{ q: 'What does ft_ultimate_range return when min >= max?', options: ['0', '-1', 'NULL', '1'], answer: '0' },
{ q: 'What does ft_ultimate_range return when malloc fails?', options: ['-1', '0', 'NULL', '1'], answer: '-1' },
{ q: 'What is the correct prototype of ft_ultimate_range?', options: ['int ft_ultimate_range(int **range, int min, int max)', 'int *ft_ultimate_range(int min, int max)', 'void ft_ultimate_range(int **range, int min, int max)', 'int ft_ultimate_range(int *range, int min, int max)'], answer: 'int ft_ultimate_range(int **range, int min, int max)' },
{ q: 'After calling ft_ultimate_range(&arr, 3, 7), what is arr[0]?', options: ['3', '7', '0', '4'], answer: '3' },
{ q: 'Why does ft_ultimate_range use a double pointer as its first parameter?', options: ['To modify the pointer in the caller scope', 'To pass a larger amount of data', 'To avoid returning a value', 'To reduce memory usage'], answer: 'To modify the pointer in the caller scope' },
{ q: 'If ft_ultimate_range returns -1, what should the caller assume?', options: ['Memory allocation failed', 'min was greater than max', 'The function succeeded with an empty range', 'The range was zero'], answer: 'Memory allocation failed' },
{ q: 'What does ft_strjoin return when the size parameter is 0?', options: ['NULL', 'A malloc\'d empty string', 'An empty string literal (read-only)', 'Undefined behavior'], answer: 'A malloc\'d empty string' },
{ q: 'In ft_strjoin, what does the size parameter represent?', options: ['The number of strings to join', 'The size of each string', 'The maximum length of the result', 'The length of the separator'], answer: 'The number of strings to join' },
{ q: 'What is the correct prototype of ft_strjoin?', options: ['char *ft_strjoin(int size, char **strs, char *sep)', 'char *ft_strjoin(char **strs, char *sep, int size)', 'void ft_strjoin(int size, char **strs, char *sep)', 'char *ft_strjoin(int size, char *strs, char *sep)'], answer: 'char *ft_strjoin(int size, char **strs, char *sep)' },
{ q: 'When size is 0 in ft_strjoin, how much memory is allocated?', options: ['0 bytes', '1 byte', 'sizeof(char *) bytes', 'No memory is allocated'], answer: '1 byte' },
{ q: 'In the result of ft_strjoin, where does the separator appear?', options: ['Between every pair of consecutive strings', 'Before every string', 'After every string', 'Only at the end'], answer: 'Between every pair of consecutive strings' },
{ q: 'What does ft_strjoin return if any memory allocation fails?', options: ['NULL', 'A partially joined string', 'An empty allocated string', 'The first string'], answer: 'NULL' },
{ q: 'How is the total length calculated for ft_strjoin(3, strs, sep)?', options: ['Sum of string lengths + sep_len * 2 + 1', 'Sum of string lengths + sep_len * 3', 'Sum of string lengths + 1', 'Sum of string lengths * sep_len + 1'], answer: 'Sum of string lengths + sep_len * 2 + 1' },
{ q: 'What does ft_strjoin(0, NULL, ",") return?', options: ['NULL', 'A malloc\'d empty string', 'An empty string literal', '","'], answer: 'A malloc\'d empty string' },
{ q: 'When size > 0 but all strings are empty in ft_strjoin, what is the result?', options: ['The separators followed by a null terminator', 'A single null terminator', 'NULL', 'An empty allocated string'], answer: 'The separators followed by a null terminator' },
{ q: 'What is the strlen of the string returned by ft_strjoin(2, ["abc", "de"], " ")?', options: ['6', '7', '8', '5'], answer: '6' },
{ q: 'What does ft_convert_base return if either base is invalid?', options: ['NULL', 'An empty allocated string', '0', 'The original number string'], answer: 'NULL' },
{ q: 'What conditions make a base invalid in ft_convert_base?', options: ['Size less than 2, contains + or -, or has duplicates', 'Size less than 10, contains letters', 'Size less than 16, contains whitespace', 'Size greater than 36, contains special characters'], answer: 'Size less than 2, contains + or -, or has duplicates' },
{ q: 'How does ft_convert_base handle negative numbers?', options: ['By checking for a leading \'-\' character', 'By using two\'s complement arithmetic', 'By checking for a \'+\' character', 'It does not support negative numbers'], answer: 'By checking for a leading \'-\' character' },
{ q: 'What is the correct prototype of ft_convert_base?', options: ['char *ft_convert_base(char *nbr, char *base_from, char *base_to)', 'int ft_convert_base(char *nbr, char *base_from, char *base_to)', 'char *ft_convert_base(char *nbr, int base_from, int base_to)', 'void *ft_convert_base(char *nbr, char *base_from, char *base_to)'], answer: 'char *ft_convert_base(char *nbr, char *base_from, char *base_to)' },
{ q: 'Which two memory functions must ft_convert_base use?', options: ['malloc and free', 'malloc and calloc', 'free and realloc', 'malloc and memcpy'], answer: 'malloc and free' },
{ q: 'If ft_convert_base encounters a character in nbr that is not in base_from, what happens?', options: ['Processing stops at that character', 'NULL is returned', 'The character is skipped', 'The function frees all memory and returns NULL'], answer: 'Processing stops at that character' },
{ q: 'What is the minimum valid size for a base in ft_convert_base?', options: ['2', '1', '10', '0'], answer: '2' },
{ q: 'What characters are explicitly forbidden in a base string for ft_convert_base?', options: ['\'+\', \'-\', and whitespace', 'Letters and digits', 'Only whitespace characters', 'Only \'+\' and \'-\''], answer: '\'+\', \'-\', and whitespace' },
{ q: 'In ft_convert_base, what should be verified first before any conversion?', options: ['The validity of both base strings', 'The length of nbr', 'Whether nbr contains a minus sign', 'Whether nbr is NULL'], answer: 'The validity of both base strings' },
{ q: 'How does ft_convert_base handle leading whitespace in nbr?', options: ['Skips over it', 'Returns NULL', 'Includes it in the result', 'Returns an empty string'], answer: 'Skips over it' },
{ q: 'If nbr is "101010" in binary (base "01") and base_to is "0123456789", what does ft_convert_base return?', options: ['"42"', '"101010"', '"21"', '"84"'], answer: '"42"' },
{ q: 'What return type does ft_convert_base have?', options: ['char *', 'int', 'void *', 'char **'], answer: 'char *' },
{ q: 'What does ft_convert_base return if malloc fails during conversion processing?', options: ['NULL', 'A partially converted string', 'An empty allocated string', 'The original nbr'], answer: 'NULL' },
{ q: 'What character marks the end of the array returned by ft_split?', options: ['NULL', '\'\\0\'', '\'\\n\'', 'EOF'], answer: 'NULL' },
{ q: 'In ft_split, what type of parameter is charset?', options: ['A string that can contain multiple separator characters', 'A single character', 'An array of integers', 'A function pointer for comparison'], answer: 'A string that can contain multiple separator characters' },
{ q: 'What does ft_split do if a memory allocation fails during processing?', options: ['Frees all previously allocated memory and returns NULL', 'Returns NULL without freeing anything', 'Returns the partially built array', 'Returns an empty array'], answer: 'Frees all previously allocated memory and returns NULL' },
{ q: 'What is the typical first algorithmic step in implementing ft_split?', options: ['Count the number of words in the string', 'Allocate the result pointer array', 'Copy the first word', 'Calculate the length of the string'], answer: 'Count the number of words in the string' },
{ q: 'Does ft_split include empty substrings in the result array?', options: ['No, empty substrings are excluded', 'Yes, every substring is included', 'Only at the beginning of the string', 'Only at the end of the string'], answer: 'No, empty substrings are excluded' },
{ q: 'What is the correct prototype of ft_split?', options: ['char **ft_split(char *str, char *charset)', 'char *ft_split(char *str, char *charset)', 'char **ft_split(char *str, char charset)', 'void ft_split(char *str, char *charset)'], answer: 'char **ft_split(char *str, char *charset)' },
{ q: 'If ft_split is called with an empty string str (""), what is returned?', options: ['A malloc\'d array containing only NULL', 'A malloc\'d empty string', 'NULL', 'An array with one empty string element'], answer: 'A malloc\'d array containing only NULL' },
{ q: 'What separates words in ft_split?', options: ['Any character found in the charset string', 'Only single-character delimiters', 'Only whitespace characters', 'Commas and semicolons'], answer: 'Any character found in the charset string' },
{ q: 'If charset is empty ("") in ft_split, how many words are returned?', options: ['One (the entire input string)', 'Zero', 'One for each character in the string', 'It depends on the input string'], answer: 'One (the entire input string)' },
{ q: 'How is cleanup typically handled in ft_split when an allocation fails mid-way?', options: ['All previously allocated strings and the pointer array are freed', 'Only the current string allocation is freed', 'The function does not perform cleanup', 'Only the pointer array is freed'], answer: 'All previously allocated strings and the pointer array are freed' },
{ q: 'What is the value of the element just after the last word string pointer in an ft_split result array?', options: ['NULL', '\'\\0\'', '0', 'A pointer to an empty string'], answer: 'NULL' },
{ q: 'How many separate malloc calls does a typical ft_split perform for a string with N words?', options: ['N + 1', 'N + 2', '2 * N', 'N'], answer: 'N + 1' },
{ q: 'In which exercise number of C07 does ft_split appear?', options: ['ex05', 'ex03', 'ex04', 'ex00'], answer: 'ex05' },
{ q: 'In which exercise number of C09 does ft_split appear?', options: ['ex02', 'ex00', 'ex01', 'ex05'], answer: 'ex02' },
{ q: 'What is the key difference between ft_split in C07 and the ft_split in C09?', options: ['There is no difference; the prototype and behavior are identical', 'C07 uses a char delimiter, C09 uses a string', 'C09 allows empty strings in the result, C07 does not', 'C07 uses malloc, C09 does not'], answer: 'There is no difference; the prototype and behavior are identical' },
{ q: 'Which module positions ft_split as its most advanced exercise?', options: ['C07', 'C09', 'C08', 'C06'], answer: 'C07' },
{ q: 'In curriculum order, which module introduces ft_split first?', options: ['C07', 'C09', 'Both at the same time', 'Neither module contains ft_split'], answer: 'C07' },
{ q: 'What is the value of NULL when cast to an integer?', options: ['0', '1', '-1', 'Undefined'], answer: '0' },
{ q: 'What happens if you call free on memory that has already been freed?', options: ['Undefined behavior', 'Nothing, free is idempotent', 'The program crashes immediately', 'The memory is marked as free again safely'], answer: 'Undefined behavior' },
{ q: 'What is the difference between NULL and \'\\0\'?', options: ['NULL is a null pointer constant, \'\\0\' is the null character', 'They are exactly the same', 'NULL is for integers, \'\\0\' is for pointers', 'NULL is 0, \'\\0\' is 1'], answer: 'NULL is a null pointer constant, \'\\0\' is the null character' },
{ q: 'What is a memory leak?', options: ['Allocated memory that is no longer referenced by any pointer', 'Memory that is freed too early', 'A buffer overflow', 'Using a variable without initializing it'], answer: 'Allocated memory that is no longer referenced by any pointer' },
{ q: 'What is the most reliable way to prevent memory leaks?', options: ['Free every allocated block when it is no longer needed', 'Use global variables for all allocations', 'Avoid using malloc entirely', 'Let the OS clean up on exit'], answer: 'Free every allocated block when it is no longer needed' },
{ q: 'What value does malloc return when it fails to allocate memory?', options: ['NULL', '0', '-1', 'A non-zero error code'], answer: 'NULL' },
{ q: 'What is a double pointer (e.g., int **)?', options: ['A pointer that points to another pointer', 'A pointer multiplied by 2', 'A pointer to an array of integers', 'An array of pointers'], answer: 'A pointer that points to another pointer' },
{ q: 'When should you check whether malloc returned NULL?', options: ['After every malloc call', 'Only for large allocations', 'Only when allocating arrays', 'Never, malloc always succeeds'], answer: 'After every malloc call' },
{ q: 'What does free(NULL) do?', options: ['Nothing, it is safe to call free on NULL', 'It causes a segmentation fault', 'It allocates new memory', 'It returns an error code'], answer: 'Nothing, it is safe to call free on NULL' },
{ q: 'What is a dangling pointer?', options: ['A pointer that points to memory that has already been freed', 'A pointer that has not been initialized', 'A pointer set to NULL', 'A pointer to a local variable'], answer: 'A pointer that points to memory that has already been freed' },
{ q: 'How do you properly free the result of ft_split?', options: ['Free each individual string, then free the main array', 'Free only the main array', 'Free only the individual strings', 'Call free on the first element only'], answer: 'Free each individual string, then free the main array' },
{ q: 'What fictional substance is mentioned in the C07 module foreword?', options: ['Concentrated dark matter', 'Unobtainium', 'Plumbus', 'Meeseeks powder'], answer: 'Concentrated dark matter' },
{ q: 'The C07 foreword compares memory allocation to handling what?', options: ['Concentrated dark matter', 'A portal gun', 'A plumbus', 'Time travel'], answer: 'Concentrated dark matter' },
{ q: 'Who invented concentrated dark matter according to the C07 foreword?', options: ['Rick Sanchez', 'Jerry Smith', 'Birdperson', 'Summer Smith'], answer: 'Rick Sanchez' },
{ q: 'What does the C07 foreword say can happen if concentrated dark matter is mishandled?', options: ['It can cause an explosion', 'It creates a portal to another dimension', 'It turns into a plumbus', 'It becomes inert'], answer: 'It can cause an explosion' },
{ q: 'What lesson does the C07 foreword teach about memory management?', options: ['Handle memory with care, just like concentrated dark matter', 'Memory allocation is always safe', 'malloc never fails', 'free is optional'], answer: 'Handle memory with care, just like concentrated dark matter' },
{ q: 'The C07 foreword suggests that ft_strdup is as essential to programming as what is to Rick?', options: ['The portal gun', 'Concentrated dark matter', 'The plumbus', 'Jerry'], answer: 'Concentrated dark matter' },
{ q: 'What is the main theme of the C07 foreword?', options: ['Memory must be allocated and freed with extreme care', 'Programming is easy and straightforward', 'malloc is the most important function in C', 'Memory leaks are acceptable for small programs'], answer: 'Memory must be allocated and freed with extreme care' },
{ q: 'In the C07 foreword comparison, what should programmers do to avoid crashes?', options: ['Always check malloc return and properly free memory', 'Never use malloc at all', 'Use global buffers instead of allocation', 'Ignore memory management and let the OS handle it'], answer: 'Always check malloc return and properly free memory' }
]