By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

printf related...

P: 10
hi!!!
Please help me out as to what would be the output of the following code and whats the reason for it????
What will be the output of the following program :
int main()
{
int val=10;
printf("%d",val+1,"%d",val--);
return(0);
}
Jun 13 '07 #1
Share this Question
Share on Google+
4 Replies


gpraghuram
Expert 100+
P: 1,275
Hi,

The output will be 10. Because the -- operator has more precedence.

Other members can add to this

Raghuram
Jun 13 '07 #2

P: 10
And what about the
"%d",val+1 part???..Why theres no contribution?
Jun 13 '07 #3

gpraghuram
Expert 100+
P: 1,275
HI,
If u see the prototype of printf it is
printf(char*s,...);
Only the first argument is taken for format specification and following values are taken as corresponding values for format specifiers.

If u specify 3 format specifiers and dosent specify 3 values then the compiler will give an error Example:- printf("%d %d%d",val);

On the other hand, if u specify one format specifier and multiple values then the compiler will discard the remaining values example is what u have given

But since the -- has more preceedence the value changes but it wont get printed

Raghuram
Jun 13 '07 #4

P: 10
hi
yah got it!!!..thanks a lot!!
Jun 14 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.