Question
Please help me with those Computer science homework problem. Thanks!! Question is below, thank you a lot!! Code: #include #include main() { int i; char
Please help me with those Computer science homework problem. Thanks!! 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 5: how many bytes will be allocated to array s1[ ] by the compiler?
(A) 1. (B) 5 (C) 6 (D) 40
2 . At line 5: char s[5], s1[ ] = "hello", s2[5] = "world"; What would happen if s[5] is replaced by s[ ]?
(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 will occur.
3 .At line 5: What is the difference if s1[ ] = "hello" is replaced by s1[ ] = {'h', 'e', 'l', 'l', 'o'} ?
(A) There is no difference.
(B) A contextual error will occur at compilation time.
(C) A semantic error will occur at compilation time.
(D) No error will be reported, but a semantic error can occur.
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