Question
Please help, those are my Computer science homework problem, Question is below, thank you a lot!! Code: #include #include main() { int i; char s[5],
Please help, those are my Computer science homework problem, Question is below, thank you a lot!!
Code:
#include
#include
main() {
int i;
char s[5], s1[ ] = "hello", s2[5] = "world"; // s2[5] = "world" incorrect;
for (i = 0; i
printf("%c", s1[ i ]);
printf(" ");
printf("s1 = %s, size = %d ", s1, sizeof s1);
for (i = 0; i
printf("%c", s2[ i ]);
printf(" ");
printf("s2 = %s, size = %d ", s2, sizeof s2); // no end of string
strcpy(s, s1); // unsafe: copy size 6 to 5
printf("s = %s, size = %d ", s, sizeof s);
}
1 . At line 14: strcpy(s, s1); What would happen if the line is replaced by s = s1; ? (A) The problem is fixed and no error at this line. (B) A contextual error will occur at compilation time. (C) The program will crash at run time. (D) No error will be reported, but a semantic error can occur. 2 . At Line 14: Which of the following statement can replace line 14 without generating a contextual or semantic error? (A) s[5] = {'h', 'e', 'l', 'l', 'o}; (B) s = "hello"; (C) s[5] = "hello"; (D) None of them
2 3 I o o o voor A #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started