if statement

hi friends.
what is output of this C program..
this one is from book let us c

#include<stdio.h>
int main()
{
int x=10,y=20;
if(x==y);
printf("%d%d\n",x,y);
return 0;
}
Why don't you run it & find out?

Or are you wondering why the output is different to what you expected?
Last edited on
yep..the output is different from what i expect..
output is 10 20
but i didn't understand that y this program is not showing error becase here if statement is followed by semicolon(;)....
Technically, there is nothing wrong with the statement if(x==y);.
You are simply saying, "If x equals y, do nothing."
But x does not equal y anyhow, so it doesn't get executed.
What is the program supposed to do?
this is due to the nature of the c++ compiler.

similarly the statement:

if (x = y)

does not produce a syntax error but does produce a logical programming error in almost all cases.

i think the idea of the example was to illustrate this.
yeah i got it but according to my knowledge the syntax of if statement is

if(condition)
{
.......
}


there is no any semicolon..
Topic archived. No new replies allowed.