Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is C Language code where the semicolon is put right after if condition plz explain me this code.
C#
#include<stdio.h>
int main()
{
    int x = 10, y = 100%90, i;
    for(i=1; i<10; i++)
    if(x != y);
        printf("x = %d y = %d\n", x, y);
    return 0;
}
Posted
Comments
SoMad 9-May-13 5:09am    
I am pretty sure it is simply a b...wait a second, is this homework?

Soren Madsen
Mohibur Rashid 9-May-13 5:20am    
virtual +5
SoMad 9-May-13 5:26am    
:) thanks.

1 solution

Such code, albeit valid, make no sense.
It checks ten times if x is different from y and if the condition is satisfied (actually it is NOT satisfied) does NOTHING (due to the semicolon after the if statement: such a semicolon is the 'empty statement').
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900