The output of the following code is 123 Genesis.I could not get it how?
Code:int fun(int num)
{
return printf(" %d ", num);
}
void main()
{
printf(" Genesis ", fun(123), " & Genesis");
}
Printable View
The output of the following code is 123 Genesis.I could not get it how?
Code:int fun(int num)
{
return printf(" %d ", num);
}
void main()
{
printf(" Genesis ", fun(123), " & Genesis");
}
Format of printf:Quote:
printf(" Genesis ", fun(123), " & Genesis");
int printf( const char *format [, argument]... );
format is the format control. If this format control includes %d, %s %c etc., th printf uses the remaining arguments to replace values accordingly. If no such thing is found, then the arguments are ignored.
your printf passes fun(123) are argument. Since it is an argument it is resolved before printf and hence 123 gets printed first. then the current printf is executed, which prints the Genesis. Other arguments are ignored.
Unless I've misunderstood your question I see nothing majorly wrong with your code and does indeed print 123 Genesis.
However, a point to note is that main should be declared as having a return type of int :
RegardsCode:int main()
{
...
return 0;
}
Well dude .. its working perfectly dude... whats the error u r getting ?Quote:
Originally Posted by erankushmehta
i dont think there must be.. but what is the output ?