Skip to main content

Printf() in if-else statement

C programming language have some control statements e.g. if statement,switch statement,Conditional operator statement ,goto statement and loop statement.
let discuss about if statement. In if statement when control jump to the if statement it will check whether condition is true or not, if condition is true then the code within if statement body will be executed if condition is false then control will jump
out of the statement block and outer part of statement of the code will run.

So if we talk about printf() in if condition then what will happen?? let see this example:




Above example will print 02. Because printf() returns number of bytes successfully written so here in if condition printf() print 0 and condition is true so control jump to i=2 initialization statement and second printf() statement will print 02. So output will be 02.This is how it does work.

Comments