Asked by Bulut Yasin on Jul 09, 2024

verifed

Verified

You can replace lines 5 and 6 in the following function with ____.
1 /* copy string2 to string1 */
2 void strcopy(char string1[], char string2[])
3 {
4 int i = 0;
5 while (string1[i] = string2[i])
6 i++;
7 }

A) while (*string1 = *string2) ;
B) while (*string1 = string2) ;
C) while (*string1++ = *string2++) ;
D) while (*++string1 = *++string2) ;

String1

A sequence of characters, typically used to represent text in programming languages.

Function

A block of code in programming that performs a specific task, defined once and can be called multiple times within a program.

  • Know how to manipulate strings using pointers in C.
verifed

Verified Answer

YH
Youssef HatimJul 13, 2024
Final Answer :
C
Explanation :
Option C is correct because it uses pointer arithmetic to copy each character from `string2` to `string1` and then increments both pointers. This effectively replaces the functionality of lines 5 and 6 in the original code, which copies characters from `string2` to `string1` one by one in a loop until it reaches the null terminator (which is represented by the condition becoming false when the copied character is '\0').