C语言常量

Constant包括4种类型:

  • 整型
  • 浮点型
  • 枚举
  • 字符型
#include <stddef.h>
#include <uchar.h>

int main() {
  /* Integer constant */
  int a01 = 1, a02 = -1000; // decimal
  int a11 = 011, a12 = -0777; // octal
  int a21 = 0xabcdef, a22 = 0XABCDEF; // hexadecimal
  long a31 = 10000l, a32 = 10000L; // long
  long long a41 = 100000000000000ll, a42 = 100000000000000LL; // long long
  unsigned a51 = 10000u, a52 = 10000U; // unsigned

  /* Floating constant */
  double b01 = 0.1, b02 = .1, b03 = 1.; // decimal
  double b11 = 1.0e3, b12 = 1.0E3, b13 = 1.e-3, b14 = 1.E-3; // exponent
  double b21 = 0xabc.defp3, b22 = 0XABC.DEFP-3; // hexadecimal
  float b31 = 1.0f, b32 = 1.0F;
  long double b41 = 1.0l, b42 = 1.0L;

  /* Enumeration constant */
  enum E {A, B, C = 10};

  /* Character constant */
  unsigned char c01 = 'a';
  unsigned char c11 = '\'', c12 = '\"', c13 = '\?', c14 = '\\', c15 = '\a', c16 = '\b',
    c17 = '\f', c18 = '\n', c19 = '\r', c1a = '\t', c1b = '\v'; // simple escape
  unsigned char c21 = '\0', c22 = '\77', c23 = '\377'; // octal escape
  unsigned char c31 = '\x0', c32 = '\xab', c33 = '\xff'; // hexadecimal escape
  wchar_t c41 = L'\xffff'; // wchar_t
  char16_t c51 = u'\xabcd'; // char16_t;
  char32_t c61 = U'\x12345678'; // char32_t
  char c71 = 'ab'; // implementation-defined

  return 0;
}

 

posted on 2013-09-30 14:16  chenkkkabc  阅读(662)  评论(0编辑  收藏  举报