Question
Complete the C function to copy at most n characters
from source starting at start_index into destination, ensuring destination is null-terminated. Assume destination has enough allocated memory. #include #include // For debugging, not strictly needed void safe_copy_substring(char* destination, const char* source, int start_index, int n) { int source_len = strlen(source); if (start_index >= source_len) { destination[0] = '\0'; // Source index out of bounds, return empty string return; } int chars_to_copy = n; if (start_index + chars_to_copy > source_len) { chars_to_copy = source_len - start_index; } strncpy(destination, _________, chars_to_copy); // Line to complete destination[chars_to_copy] = '\0'; // Ensure null-termination }Solution
Correct Answer: E (Both source + start_index and &source[start_index] correctly provide a pointer to the starting character of the substring within source.)
There is a school by the side of the road. Three children of nursery class stray away from the school on to the road. A truck driver, who was driving t...
In which case, while fastening the liability on the accused, the Court stated that – “They also serve who only stand and wait”?
The term debt has been defined under IBC as _________________
Money Bills shall not be introduced in:
What does the term "central recordkeeping agency" refer to?
Which landmark case held that general consent of a State under Section 6 can be withdrawn?
How many persons are needed to call robbery a dacoity?
Which of the following is not true about High Courts in India?
On the direction of State Government duty may be levied on excisable articles:
Consider the following statements regarding scheduled offences under PMLA, 2002:
Statement 1: Scheduled offences are limited to those listed u...