As a new C programming learner, I'm trying to understand which specifier I should use in printf to display the maximum and minimum values of a long double type. Per the following StackOverflow answer, I can use %Lg: https://stackoverflow.com/a/18797417/1536240
But that doesn't seem to do the trick. I've tried %e, %f, %Lf, %g and %Lg, but it's not working. Here's the relevant part of my code I'm having issues with (the rest of the stuff I'm doing's working fine):
printf("**long double**\nStorage size: %d bytes \t Minimum value: %Lg
\t Maximum value: %Lg\n", sizeof(long double), LDBL_MIN, LDBL_MAX);
I've included these header files at the top:
#include <stdio.h>
#include <limits.h>
#include <float.h>
I'm kinda lost here.
EDIT: Sorry for not explaining what the output is. I'm using %Lg right now, and I'm getting this in the terminal.
While you should provide the obtained results in your question, your mistake likely is to use
%d
to print the result ofsizeof
, which should be printed with%zu
.This causes undefined behavior. For some platforms, the rest of
printf
's arguments, on the stack, will be misinterpreted because the width ofint
does not match the width ofsize_t
.