+ 28
Can anyone tell me what the exact reason of different output??
printf("%c",49); output-1 printf("%d",49); output-49 printf("%f",49); output-0.000 please help .....
9 Answers
+ 14
Reason : You Are Using Different Format Specifier
1) The %c format specifier is implemented for representing characters. This is used with printf() function for printing the character stored in a variable. When you want to print a character data, you should incorporate the %c format specifier.
or
we can pass the ASCII of that character ..
------------------------------------
Output is 1 because 49 is ASCII of 1
------------------------------------
2) The %d format specifier is implemented for representing integer values. This is used with printf() function for printing the integer value stored in the variable.
------------------------------------
49 is an integer value so output is 49
------------------------------------
3) The %f format specifier is implemented for representing fractional values. This is implemented within printf() function for printing the fractional or floating value stored in the variable. Whenever you need to print any fractional or floating data, you have to use %f format specifier.
------------------------------------
you are passing 49 which is not a fractional or floating
value ..49 is an Integer value
so output is 0.000 which is initial floating no.
------------------------------------
-ty("đ");
+ 24
thank u so much friends đ
+ 24
thanks Sudhir đ
+ 4
The output is different as you are using different data type specifiers
%c is for character
%d for integer and
%f for float
Therefore your output is according to that
+ 3
in the first line you set it to character and you clearly do not use a character in there. for the second, you ue int and send int, so it is ok. the third one needs floating point values and again, you send an integer and not a character. try casting them to the respective type or send a valid type instead. Also take a look at the "c printf modifiers" to make all of that clean
+ 3
As ur using different format specifier ur getting different outputs %c converting 49 to ascii value %d print it as int 49
u have done mistake in %f as %f is used for floating values and ur passing an int it's outputting 0.000
pass 49.0
+ 3
nice explanation brother
+ 3
just look at the format specifier...
+ 1
1st: 49 is the ASCII code of 1, so when you write %c, it means you want to print the character of this ASCII code that you are given.
2nd: similarly %d, prints the intiger value only, so it prints 49 as it is. because 49 is also an integer value.
3rd: At last %f, prints only float value(decimal number). so because 49 is an integer value and the other hand you used %f..so it doesn't matched and the output becomes 0.00000