Questions tagged [length-modifiers]

5 questions
194
votes
5 answers

Why does scanf() need "%lf" for doubles, when printf() is okay with just "%f"?

Why is it that scanf() needs the l in "%lf" when reading a double, when printf() can use "%f" regardless of whether its argument is a double or a float? Example code: double d; scanf("%lf", &d); printf("%f", d);
raldi
  • 21,344
  • 33
  • 76
  • 86
4
votes
2 answers

How to separate format specifiers from characters with printf

Another way to phrase this question might be "How to end format specifiers in printf" If I want to print microseconds in this format 100us using the following code... long microseconds = 100L; printf("%lus", microseconds); only prints 100s because…
4
votes
2 answers

What is the difference between the %PRId and %d format characters?

Consider the following code: #include #include void main(void) { int32_t a = 44; fprintf(stdout, "%d\n", a); fprintf(stdout, "%"PRId32"\n", a); } When is it better to use %d and when would it be better to use…
user7659542
0
votes
1 answer

Format specifier %Lf for long double in C is not working as if expected

While studying the C essentials from online video, the author shared the code below to find the difference between float, double and long double. I ran this program in Eclispse running in 64 bit Windows 10 Laptop. #include #include…
-1
votes
1 answer

About conversion specifier of scanf in C

I have a question about conversion specifier of scanf in C. #include int main(void) { int num1; scanf("%hhd",&num1); printf("%d \n",num1); } Since I have typed "%hhd" as the conversion specifier in scanf function, when my…
Jin
  • 1,902
  • 3
  • 15
  • 26