What will be the output of the following program?
#include <stdio.h>
#include <string.h>
int main() {
char str1[20] = "Hello";
char str2[20] = "Hello";
strcpy(str2, str1);
if (strcmp(str1, str2) 0)
printf("Equal\n");
else
printf("Not Equal\n");
return 0;
}
Explanation
This program contains a syntax error that prevents it from compiling successfully.
Missing Operator: In the if statement, the condition if (strcmp(str1, str2) 0) is syntactically incorrect.
Comparison Logic: The strcmp function returns an integer (0 if strings are equal). To compare this result against 0, a relational operator (such as ==) must be used. The provided code is missing this operator.
The correct syntax for comparing these strings should be:
Correct Condition⟹strcmp(str1,str2)==0
Since the provided snippet lacks the required equality operator ==, the C compiler will flag a syntax error at that line.
Because the expression does not follow standard C syntax rules, the code fails to build, leading to a Compiler Error.