home > 写経編 > 柴田望洋『明解C言語 入門編』 > 7. 基本型 >

ForNext

Only Do What Only You Can Do

059. 型の表現範囲を表示

VBScript

JScript

Perl

PHP

Python

Ruby

PowerShell

Scala

F#

C

更新日 : 2010.10.08
#include <stdio.h>
#include <limits.h>
#include <values.h>

int main(int argc, char* argv[])
{
    printf("char                 : %d 〜 %d\n", CHAR_MIN,  CHAR_MAX);
    printf("signed char          : %d 〜 %d\n", SCHAR_MIN, SCHAR_MAX);
    printf("unsigned char        : %d 〜 %d\n", 0,         UCHAR_MAX);

    printf("int                  : %d 〜 %d\n", INT_MIN, INT_MAX);
    printf("unsigned int         : %u 〜 %u\n", 0,       UINT_MAX);

    printf("short int            : %d 〜 %d\n", SHRT_MIN, SHRT_MAX);
    printf("unsigned short int   : %d 〜 %d\n", 0,        USHRT_MAX);

    printf("long int             : %ld 〜 %ld\n", LONG_MIN, LONG_MAX);
    printf("unsigned long int    : %lu 〜 %lu\n", 0,        ULONG_MAX);

    printf("float                : %g 〜 %g\n",   MINFLOAT,   MAXFLOAT);
    printf("double               : %g 〜 %g\n",   MINDOUBLE,  MAXDOUBLE);
    printf("long double          : %Lg 〜 %Lg\n", MINLDOUBLE, MAXLDOUBLE);

    return 0;
}
R:\>lesson059\project1.exe
char                 : -128 〜 127
signed char          : -128 〜 127
unsigned char        : 0 〜 255
int                  : -2147483648 〜 2147483647
unsigned int         : 0 〜 4294967295
short int            : -32768 〜 32767
unsigned short int   : 0 〜 65535
long int             : -2147483648 〜 2147483647
unsigned long int    : 0 〜 4294967295
float                : 1.17549e-38 〜 3.40282e+38
double               : 2.22507e-308 〜 1.79769e+308
long double          : 3.3621e-4917 〜 1.18973e+4932

C++

C++Builder

VC++

C#

Java

更新日 : 2010.11.05
class Lesson059 {
    public static void main(String[] args) {
        System.out.printf("short                : %d 〜 %d\n", Short.MIN_VALUE,   Short.MAX_VALUE);
        System.out.printf("int                  : %d 〜 %d\n", Integer.MIN_VALUE, Integer.MAX_VALUE);
        System.out.printf("long                 : %d 〜 %d\n", Long.MIN_VALUE,    Long.MAX_VALUE);
        System.out.printf("float                : %f 〜 %f\n", Float.MIN_VALUE,   Float.MAX_VALUE);
        System.out.printf("double               : %f 〜 %f\n", Double.MIN_VALUE,  Double.MAX_VALUE);
    }
}
L:\>java Lesson059
short                : -32768 〜 32767
int                  : -2147483648 〜 2147483647
long                 : -9223372036854775808 〜 9223372036854775807
float                : 0.000000 〜 340282346638528860000000000000000000000.000000
double               : 0.000000 〜 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000

Objective-C

D

VB

VB.NET

Delphi

更新日 : 2010.09.24
program Project1;

{$APPTYPE CONSOLE}

uses
    SysUtils, Math;

procedure main();
var
    a: Shortint;
    b: Smallint;
    c: Longint;
    d: Byte;
    e: Word;
    f: Integer;
    g: Cardinal;
    o: Single;
    p: Double;
    q: Extended;
    r: Real;
    v: Comp;
    x: Currency;
    y: Extended;
begin
    writeln(format('ShortInt : %d〜%d', [low(a), high(a)]));
    writeln(format('SmallInt : %d〜%d', [low(b), high(b)]));
    writeln(format('LongInt  : %d〜%d', [low(c), high(c)]));
    writeln(format('Byte     : %d〜%d', [low(d), high(d)]));
    writeln(format('Word     : %d〜%d', [low(e), high(e)]));
    writeln(format('Integer  : %d〜%d', [low(f), high(f)]));
    writeln(format('Cardinal : %u〜%u', [low(g), high(g)]));

    writeln(format('Single   : %g〜%g', [MinSingle,   MaxSingle]));
    writeln(format('Double   : %g〜%g', [MinDouble,   MaxDouble]));
    writeln(format('Extended : %g〜%g', [MinExtended, MaxExtended]));
    writeln(format('Comp     : %g〜%g', [MinComp,     MaxComp]));

//  writeln(format('Currency :
end;

begin
    main;
end.
S:\>lesson059\project1.exe
ShortInt : -128〜127
SmallInt : -32768〜32767
LongInt  : -2147483648〜2147483647
Byte     : 0〜255
Word     : 0〜65535
Integer  : -2147483648〜2147483647
Cardinal : 0〜4294967295
Single   : 1.5E-45〜3.4E38
Double   : 5E-324〜1.7E308
Extended : 3.4E-4932〜1.1E4932
Comp     : -9.22337203685478E18〜9.22337203685478E18

Ada

PL/SQL

T-SQL

関数型

inserted by FC2 system