Tuesday, February 22, 2011

small braces with functions......

While playing with the programs i certainly come up with the strange thing that samll braces does not matter with functions ....I mean to say that they does not matter if closed properly...
let us make this more clear by the help of an example....

#include<stdio.h>
#include<conio.h>
void func(int);
void main()
{
int f=20;
func(f);
getch();
}
void func(int num)
{
printf("num is:%d",num);
}

Everybody knows the output yes you are thinking right the output is:
num is:20

Now coming to the point,everybody knows about function declaration,function definition,function calling and i am not going to explain that...

change function calling statment to
(func(f));,
 ((func(f)));,
 (((func(f)))); and any number of braces but the conditions is that the braces must be balanced....that is you can't say ((func(f))
you will get the same output,the same applies with function definition and function calling....

function declaration:
void func(int);, 
void (func(int));, 
void((func(int)));, 
void (((func( int)))); and with any number of balanced braces are equivalent and does not lead to any compiler error....

function definition:
void func(int num), 
void (func(int num)), 
void ((func(int num))) and with any number of balanced braces are equivalent and does not lead to compiler error..

Are you amazed?????? And dun agree with me...run the follwing one and respond to this post.........

#include<stdio.h>
#include<conio.h>
void ((((func(int)))));
int (main())
{
    int f=20;
clrscr();
((func(f)));
    getch();
    return 0;
}
void (((((((func(int n))))))))
{
     printf("this is %d",n);
}

Note::missing braces in the above example may be a due to the editor ,please be sure that braces are balanced,because i know you are going to check it for sure.......