MCN Professionals | Interview Question of the day
MCN Professionals is starting Industrial Training for MCA-2012 Batch. Have a look at our Industrial Training Program and Course Details.
-----------------------------------------------------------------------------------------------------------------------------------------
Today's Question:
Write a program in C language which does not have even a single semicolon, but prints 'Hello World'.
Solution:
Semicolon is used to terminate a statement in C language, but null statement can be written in two ways:
; // Empty or NULL Statement
{} // Empty of NULL Statement
The below program uses this fact, to print 'Hello World without having any semicolon in it:
#include
<stdio.h>
int main()
{
while( ! printf("Hello World") )
{
}
}
Output:
Hello World
Note that printf returns the number of characters printed. In this case ptintf will return 11 (including the space character). 11 in C language is true, and control will not enter loop even once (Hence 'Hello World' will be printed only once).
---------------------------------------------------------------------------
Interview Questions Archive:
To see all the questions in the category click
here...