First of all you have to realize that compiler just compiles your code. If compilation is ok, there is tester, that checks your program using several test files. You can imagine that this comparison is similar to diff - output of your program is compared to correct answer. If there is a difference, tester judges your code with “wrong answer”.
In case this is not a snippet but the full program , where are the statements that give the output . They are missing from your code which you are saying you submitted .
Of course you will get wrong answer if you dont print any output .
Also you should not say that compiler gives wrong answer , compiler can only give compile time error . Wrong answer is generated only when your program compiled successfully , ran successfully within time limits but its answer did not match the required answer .