|
-
April 7th, 2006, 05:17 AM
#1
output confusion
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");
}
Regards,
Ankush Mehta
"The Child is the father of the Man."
William Wordsworth
-
April 7th, 2006, 05:35 AM
#2
Re: output confusion
printf(" Genesis ", fun(123), " & Genesis");
Format of printf:
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.
Sarve Bhavantu Sukheenah,
Sarve Santu Niramayah,
Sarve Bhadrani Pashyantu,
Ma Kashchit dukh bhag bhavet.
-
April 7th, 2006, 05:38 AM
#3
Re: output confusion
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 :
Code:
int main()
{
...
return 0;
}
Regards
I don't mind that you think slowly but I do mind that you are publishing faster than you think. Wolfgang Pauli, physicist, Nobel laureate (1900-1958)
-
April 7th, 2006, 07:21 AM
#4
Re: output confusion
 Originally Posted by erankushmehta
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");
}
Well dude .. its working perfectly dude... whats the error u r getting ?
i dont think there must be.. but what is the output ?
It takes seconds for rating…that actually compensates the minutes taken for giving answers
The biggest guru-mantra is: Never share your secrets with anybody. It will destroy you.
Regards, Be generous->Rate people
Jayender!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|