I have a doudbt about following.


Joined
Oct 4, 2018
Messages
1
Reaction score
0
what will be the value of variable c ?

main()
{
int a=10,c;
c=printf("%d",a);
printf("%d",c);
}
 
Ad

Advertisements

Ad

Advertisements

Joined
Jun 27, 2018
Messages
12
Reaction score
5
Initially the value of c could be anything, because it has not been initialised.

And if you take a look at the function signature of printf, you will see that it returns an int, which represents the number of characters that printf wrote to the screen.
So in this line:
Code:
c=printf("%d",a);
printf is called, passing the value of a (which is 10) - causing the string "10" to be printed to the screen. The string "10" contains two characters, so the printf function will return the value 2, which will be assigned to the variable c.
So the final value of c will be 2.
And because there are no newline characters or spaces in the output in any of the printf statements, your program will output:
102

Where "10" is the value of a and "2" is the value of c.

Does that make sense?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top