Question
A C function attempts to copy a substring.
#include #include #include char* copy_substring(const char* source, int start_index, int length) {   char* dest = (char*)malloc(length + 1);   if (dest == NULL) return NULL;   strncpy(dest, source + start_index, length);   dest[length] = '\0'; // Null-terminate   return dest; } int main() {   const char* original = "Programming"; // Length 11   char* sub = copy_substring(original, 5, 10); // start_index=5, length=10   if (sub) {     printf("Substring: %s ", sub);     free(sub);   }   return 0; } What is the most likely issue with copy_substring when called as in main?Solution
Correct Answer: B (source + start_index points to "mming". length is 10. strncpy will attempt to copy 10 characters starting from 'm'. However, "mming" only has 5 characters. strncpy will read 5 characters from "mming" and then 5 more characters from memory *after* "Programming", potentially causing a read out of bounds.)
- The divisor is 50% of the quotient and 7 times the remainder. If the remainder is 2, then what is the dividend?
How many numbers in the range from 200 to 800 are divisible by 4, 8, and 16?
- Find the median of the following observations:
25, 30, 35, 45, 40, 55, 50 - If median is 6 more than the mean, then find the difference between mode and median.
385! In the trailing Zeros, let us know.
- Find the remainder when the denominator of 'k' is divided by its numerator, if 'k' is the fraction to be subtracted from (3/4) to result in (1/6).
The sum of the exponents of the prime factors in the prime factorization of 588 is
Find the sum of the first 45 natural numbers.
Find a positive number which when increased by 26 is equal to 120 times the reciprocal of the number?
The sum of the squares of three natural numbers is 342. These numbers are in the ratio of 3:5:2. Determine the difference between the largest and smalle...