Hossain Hossain - 8 months ago 35
C Question

When i give negative number, why don't work first function?

When i give any negative input number, why don't work the first function? Thank you.

int main()
int y=-4;
printf("i"); /*This line*/

return 0;


The 'if' statement operates on a code block, i.e. if the condition is true then the following code block is executed otherwise it passes to the next. A code block can consist of a single line or a collection of lines enclosed in braces, e.g. '{ some lines of code }'

Your example has a single line following the if statement:


so if y is greater than zero then print "i". You have set y to less than zero so the condition is false and nothing is printed by that line. Execution then continues at the next line:


Hopefully that explains why it doesn't work as you are expecting. I'd recommend more time spent studying the basics of the C language and program flow.