So in my finals there was an exercise asking what will the program print.
This is the code:
#include <stdio.h>
int main (){
int x=5, y=4;
if (x>y);
printf("A");
if(x=4)
printf("%d",x+y);
return 0;
}
When I try to compile it using gcc -ansi -pedantic -Werror on a Debian machine, it compiles just fine and outputs "A8".
However, when I try to compile it using clang -ansi -pedantic -Werror, I receive errors regarding the if (x=4) expression missing = and missing statement on if(x>y);.
Why does that happen, and which answer could be marked as correct?
=is not the same operator as==.gccis believing that you know what you are doing, whileclangis not :)if (x>y); printf("A");is equal toif (x>y) { /* empty block */ } printf("A");gcc -Wall -Wextra -Wpedanticmake any difference?