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 == NUL
- L 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?
More IT Operating System Questions
- Which CPU scheduling algorithm gives preference to processes with shorter CPU burst times?
- Which probability distribution is most widely used to model channel noise in pulse code modulation?
- Which type of relationship does inheritance represent?
- Which is not an IoT OS?
- Which service model offers virtual machines and storage resources?
- What is a primary feature of the Agile Model in software development?
- What is 'virtual memory' in Operating Systems?
- What is the keyword used in Java to indicate that a class is inheriting from another class?
- A developer is choosing between an array and a linked list to store a collection of elements. If the primary operations will be frequent insertions and del...
- Which algorithm is used in game playing for decision making?
Hey! Ask a query
Please enter email id
The email must be a valid email address.
Please enter Mobile Number
Please enter valid Mobile Number
Please enter your Doubt