Wednesday, September 15, 2010

Write printf() and scanf() statement without semi-colon(;)

Print statement:

main()
{
int a;
clrscr();
if(scanf("%d",&a))
{}
if(printf("%d"),a)

{}
}


output:
2
2

Here in output,i entered 2 is given as input that is scanned and stored in variable 'a',then it is printed out 2 using printf(). Note that after if statement i used set of braces({}) to show that next statement to be executed after if. If the braces are omitted then error -"; statement missing" is produced.

The above program can be re-written as follows:

main()
{
int a;
clrscr();
if(scanf("%d",&a))
 ;
if(printf("%d"),a)

 ;
}

No comments:

Post a Comment