Wednesday, March 20, 2013

Program to use printf() without semicolon

A surprising program,
printf() function call without semicolon !!

Whenever we use a printf() function or any function which ends with semicolon ( ; ), and if we not place the semicolon at the end, then compiler gives an error like "Statement missing ;"

Then how can we do this ??
Check this program which prints a static string without semicolon..



The logic behind is that, an  if statement returns false or zero (0) only when the condition is false or zero (0). In all other cases it returns true, you can try any positive value, any string, character, or any negative value at place of zero (0) in below program. This will explain how a conditional statement works.



Some other programs that also works on this concept:-
Below program is using looping statement for and while. These statements also use condition checking so, they also follows the properties of  if statement mentioned earlier.
Here in program I have also used break statement to break the loop. If break is not used then loop will go infinite.

Powered by Blogger.