Q. What will be the output of the following C code?
Code:
#include <stdio.h>
int main()
{
char str1[] = "Hello";
char str2[10];
str2 = str1;
printf("%s,%s", str1, str2);
return 0;
}
β
Correct Answer: (D)
Error
Explanation: There will be a compilation error, because we cannot assign a string like this (str2 = str1). To resolve this issue, we have to use strcpy(str2,str1).
The output will be:
main.c:8:10: error: assignment to expression with array type
8 | str2 = str1;
| ^