C/printf: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
Stryn (dyskusja | edycje)
rv vandalism
Linia 109:
 
===Przykład użycia===
 
 
====pierwszy====
<source lang="c">
#include <stdio.h>
Linia 179 ⟶ 182:
</source>
------->
====Liczby całkowite====
 
<source lang =c>
/*
 
gcc l.c -lm -Wall
./a.out
 
 
http://stackoverflow.com/questions/29592898/do-long-long-and-long-have-same-range-in-c-in-64-bit-machine
*/
#include <stdio.h>
#include <math.h> // M_PI; needs -lm also
#include <limits.h> // INT_MAX, http://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html
 
 
 
 
 
int main(){
 
double lMax;
 
 
lMax = log2(INT_MAX);
printf("INT_MAX \t= %25d ; lMax = log2(INT_MAX) \t= %.0f \n",INT_MAX, lMax);
 
lMax = log2(UINT_MAX);
printf("UINT_MAX \t= %25u ; lMax = log2(UINT_MAX) \t= %.0f \n", UINT_MAX, lMax);
 
lMax = log2(LONG_MAX);
printf("LONG_MAX \t= %25ld ; lMax = log2(LONG_MAX) \t= %.0f \n",LONG_MAX, lMax);
 
 
lMax = log2(ULONG_MAX);
printf("ULONG_MAX \t= %25lu ; lMax = log2(ULONG_MAX) \t= %.0f \n",ULONG_MAX, lMax);
 
lMax = log2(LLONG_MAX);
printf("LLONG_MAX \t= %25lld ; lMax = log2(LLONG_MAX) \t= %.0f \n",LLONG_MAX, lMax);
 
lMax = log2(ULLONG_MAX);
printf("ULLONG_MAX \t= %25llu ; lMax = log2(ULLONG_MAX) \t= %.0f \n",ULLONG_MAX, lMax);
 
 
 
 
 
return 0;
}
 
 
 
</source>
 
Wynik :
 
<pre>
INT_MAX = 2147483647 ; lMax = log2(INT_MAX) = 31
UINT_MAX = 4294967295 ; lMax = log2(UINT_MAX) = 32
LONG_MAX = 9223372036854775807 ; lMax = log2(LONG_MAX) = 63
ULONG_MAX = 18446744073709551615 ; lMax = log2(ULONG_MAX) = 64
LLONG_MAX = 9223372036854775807 ; lMax = log2(LLONG_MAX) = 63
ULLONG_MAX = 18446744073709551615 ; lMax = log2(ULLONG_MAX) = 64
 
</pre>
 
===Uwagi===