If you have any query feel free to chat us!
Happy Coding! Happy Learning!
In addition to %d
and %u
for integers, here are some other commonly used format specifiers in C:
%f
: for floating-point numbers.%c
: for characters.%s
: for strings.%x
or %X
: for hexadecimal integers (lowercase or uppercase).%o
: for octal integers.%p
: for pointers.%%
: for printing a literal %
character.%e
or %E
: for scientific notation of floating-point numbers.%g
or %G
: for either %f
or %e
whichever is shorter.%ld
, %lld
, %Lf
etc : for long and long long data types.For example, the following code would print a floating-point number and a string:
Copy code
float pi = 3.14159;
char name[] = "John Doe";
printf("Pi is approximately %f and my name is %s", pi, name);
This will output:
Copy code
Pi is approximately 3.14159 and my name is John Doe
Note that, depending on the system you are using, there may be variations in the format specifiers for different types of data.
Comments: 0