+ 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 .....

1st May 2018, 12:10 PM
Jyoti Giri
9 Respuestas
+ 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("😊");
2nd May 2018, 1:44 AM
ㅤ Tweetu 😆 ㅤㅤ
ㅤ  Tweetu 😆 ㅤㅤ - avatar
+ 24
thank u so much friends 😊
1st May 2018, 1:04 PM
Jyoti Giri
+ 24
thanks Sudhir 😊
2nd May 2018, 1:45 AM
Jyoti Giri
+ 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
19th Aug 2018, 7:16 AM
POONAM
POONAM - avatar
+ 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
1st May 2018, 12:45 PM
Paul
+ 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
1st May 2018, 12:49 PM
Yugabdh
Yugabdh - avatar
+ 3
nice explanation brother
4th May 2018, 5:33 PM
VijaySharli
VijaySharli - avatar
+ 3
just look at the format specifier...
4th May 2018, 5:34 PM
VijaySharli
VijaySharli - avatar
+ 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
19th Jul 2018, 6:49 AM
Pushpajit-Biswas
Pushpajit-Biswas - avatar