+ 2
PLEASE EXPLAIN !
Can any one explain me in detail what are %d,%f,%c in C language !
1 Answer
+ 7
In C programming language, printf() function is used to print the âcharacter, string, float, integer, octal and hexadecimal valuesâ onto the output screen.
%d, %f, etc - they are format specifiers.
%d - we use it to display integer variables
-||- = i use it to replace "we use it to display"
%f - -||- floating variables
%c - -||- character variables
%s - -||- string variables
%lf - -||- double variables
%x - -||- hexa zecimal variables
when you try to print to the screen in this scenario:
char h = "a";
printf ("This is the character h i was talking about");
it will print the string as it sees it, but perhaps you wanted it to print "a" instead of "h" because the last one you passed it as a variable. To do that you can use the %c format specifier like this:
char h = "a";
printf ("This is the character %c i was talking about", h);
As you can see after the string to be printed on the screen i put a comma "," and then i specified with what character variable to replace the %c format specifier.
Hope this helped you