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 "amming". length is 10. strncpy will attempt to copy 10 characters starting from 'm'. However, "amming" only has 6 characters. strncpy will read 4 characters from "amming" and then 6 more characters from memory *after* "Programming", potentially causing a read out of bounds.)
Comprehensive economic partnership agreement is signed between which two countries?
What strategic objective does the Inter-Governmental Framework Agreement between India and the UAE aim to fulfill?
During the inauguration of Bharat Mandapam at Pragati Maidan, New Delhi, the Prime Minister of India released special G20 postage stamps and coins. What...
Match list I with list II and select the correct answer using the code given below the list
When did Michael Faraday discover electromagnetic induction, the principle behind the electric transformer and generator?
What was the total value of wheat exported from India in the fiscal year 2024, following restrictions imposed in May 2022 to prioritize domestic consump...
The highest surcharge rate of 37% on income above 5 crores shall be reduced to ______ % under the new tax regime?
How many dance forms have been acknowledged by Sangeet Natak Akademi as classical dance forms of India as on November 2020?
Which Indian cricketlegend was recently awarded honorary membership ofthe prestigious Melbourne Cricket Club (MCC) during the India-Australia Boxing Day...
Four letter-clusters have been given, out of which three are alike in some manner and one is different. Select the one that is different.