Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
Main ()
{
 Char ch = 'A';                 
 ch = ch+1;
 printf ("%c", ch);
 Int a = ch;
 Printf ("%d", a);
}
OUTPUT:B66

C++
Main ()
{
 Char ch = 'A';
 ch = ch+1;
 Int a = printf ("%c", ch);
 Printf ("%d", a);           
}
OUTPUT:B1

why 2nd program should give an unknown value for integer a?

What I have tried:

The return type of printf function is an integer. Why cannot i store its value in int a?
Posted
Updated 23-Jul-18 4:10am
v2

1 solution

First of all - C/C++ is case sensitive, which means that your code goes nowhere as it is...

I assume you understand why the first snippet prints 'B66' so I explain the second one only...

printf - on success - returns the number of the characters printed, in your case 1, so a will be 1 and that will give you 'B1'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900