当前位置:天才代写 > tutorial > C语言/C++ 教程 > 学点C语言(13):数据范例 – 整型、字符型和浮点型的扩展

学点C语言(13):数据范例 – 整型、字符型和浮点型的扩展

2017-11-03 08:00 星期五 所属: C语言/C++ 教程 浏览:399

副标题#e#

整型int可添加short和long:
short int:简为short;
long int: 简为long;
long long int: 简为long long

它们都可以再添加 unsigned:
unsigned int:      简为unsigned
unsigned short int:   简为unsigned short
unsigned long int:   简为unsigned long
unsigned long long int: 简为unsigned long long

char 可添加 unsigned:
unsigned char

double 可添加 long:
long double

1. short 的最小、最大值:

#include <stdio.h>
#include <limits.h>

int main(void)
{
  short n1 = SHRT_MIN;
  short n2 = SHRT_MAX;
  printf("%d .. %d\n", n1,n2);
  getchar();
  return 0;
}

2. long 的最小、最大值:

#include <stdio.h>
#include <limits.h>

int main(void)
{
  long n1 = LONG_MIN;
  long n2 = LONG_MAX;
  printf("%ld .. %ld\n", n1,n2);
  getchar();
  return 0;
}

3. long long 的最小、最大值:

#include <stdio.h>
#include <limits.h>

int main(void)
{
  long long n1 = LLONG_MIN;
  long long n2 = LLONG_MAX;
  printf("%lld .. %lld\n", n1,n2);
  getchar();
  return 0;
}


#p#副标题#e#

4. unsigned 系列的最小值都是 0:

#include <stdio.h>
#include <limits.h>

int main(void)
{
  unsigned short   n1 = USHRT_MAX;
  unsigned      n2 = UINT_MAX;
  unsigned long   n3 = ULONG_MAX;
  unsigned long long n4 = ULLONG_MAX;

  unsigned char    c = UCHAR_MAX;
  
  printf("0 .. %u\n", n1);
  printf("0 .. %u\n", n2);
  printf("0 .. %lu\n", n3);
  printf("0 .. %llu\n", n4);

  printf("\n0 .. %u\n", c);
  
  getchar();
  return 0;
}

5. long double 的最小、最大值:

#include <stdio.h>
#include <float.h>

int main(void)
{
  long double ld1 = LDBL_MIN;
  long double ld2 = LDBL_MAX;
  printf("%Le .. %Le\n", ld1,ld2);
  getchar();
  return 0;
}

返回“学点C语言 – 目次”

 

    关键字:

天才代写-代写联系方式