Note that there are some explanatory texts on larger screens.

plurals
  1. POprinting the ranges of fundamental datatypes in c
    primarykey
    data
    text
    <p>I was trying the solve the problem of printing the ranges of fundamental datatypes in C.</p> <p>but I see that the values are wrong. Can anyone please point out my error ? </p> <pre><code>#include&lt;stdio.h&gt; #include&lt;limits.h&gt; #include&lt;float.h&gt; main() { FILE *fp=fopen("/*path to the file*/","w"); fprintf(fp,"Printing the ranges for data types:\n"); fprintf(fp,"Type Min_Value Max_Value Range\n"); fprintf(fp,"*************************************************************************************************************************************************\n"); fprintf(fp,"char %4d %4d%4d\n\n",CHAR_MIN,CHAR_MAX,CHAR_MAX-CHAR_MIN); fprintf(fp,"uchar 0 %4d %4d\n\n",UCHAR_MAX,UCHAR_MAX); fprintf(fp,"schar %d %4d %4d\n\n",SCHAR_MIN,SCHAR_MAX,SCHAR_MAX-SCHAR_MIN); fprintf(fp,"int %li %li %lu\n\n",(INT_MIN,INT_MAX,INT_MAX-INT_MIN)); fprintf(fp,"uint %d %lu %u\n\n",0,UINT_MAX,UINT_MAX); fprintf(fp,"long %lli %llu %llu\n\n",LONG_MIN,LONG_MAX,LONG_MAX-LONG_MIN); fprintf(fp,"ulong %ll %ll %lu\n\n",0,ULONG_MAX,ULONG_MAX); fprintf(fp,"short %ll %ll %ld\n\n",SHRT_MIN,SHRT_MAX,SHRT_MAX-SHRT_MIN); fprintf(fp,"ushort %ld %ll %ld\n\n",0,USHRT_MAX,USHRT_MAX); fclose(fp); } </code></pre> <p>this is the output</p> <pre><code>Printing the ranges for data types: Type Min_Value Max_Value Range ************************************************************************************************************************************************* char -128 127 255 uchar 0 255 255 schar -128 127 255 int -1 127 255 uint 0 4294967295 4294967295 long 9223372034707292160 18047113275375615 18047512710020968 ulong 0 short -32768 ushort 0 65535 </code></pre> <p>after updating the code and using the format specifiers the values for int and unsigned int and long are wrong here is the update.</p> <pre><code>printf("int %15d %15d %15u\n\n",INT_MIN,INT_MAX,INT_MAX-INT_MIN); printf("uint %u %15u %15u\n\n",0,UINT_MAX,UINT_MAX); printf("long %15l %15l %15lu\n\n",LONG_MIN,LONG_MAX,LONG_MAX-LONG_MIN); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload