非常教程

C参考手册

C 语法

character constant

句法

' c-char '

(1)

u ' c-char ' (since C11)

(2)

U ' c-char ' (since C11)

(3)

L ' c-char '

(4)

' c-char-sequence '

(5)

如下:

  • c-char为:
    • 来自基本源字符集的字符减去单引号('),反斜线(\)或换行符。
    • 转义序列:转义序列中定义的特殊字符转义\' \" \? \\ \a \b \f \n \r \t \v,十六进制转义\x...或八进制转义\...之一。

通用字符名称,\ u ...或\ U ...在转义序列中定义。

(自C99以来)

    -  c-char-sequence is a sequence of two or more c-chars. 

1)单字节整数字符常量,例如 'a'或'\ n'或'\ 13'。 这样的常量的类型为int,值等于执行字符集中c-char的表示,作为char类型映射到int的值。 如果c-char在执行字符集中不能表示为单个字节,则该值是实现定义的。

2)16位宽字符常量,例如 u'貓',但不是u'?' (u'\U0001f34c')。 这种常量的类型为char16_t,值等于mbrtoc16(通常为UTF-16)生成的16位编码中的c-char的值。 如果c-char不可表示或映射到多个16位字符,则该行为是实现定义的。

3)32位宽的字符常数,例如U'貓'U'?'。这种常量的类型char32_t和值等于mbrtoc32(通常为UTF-32)生成的32位编码中的c-char值。如果c-char不可表示或映射到多个32位字符,则该行为是实现定义的。

4)宽字符常量,例如L'β'L'貓。这样的常量的类型wchar_t和值等于执行宽字符集中c-char的值(即将生成的值mbtowc)。如果c-char不可表示或映射到多个宽字符(例如,wchar_t为16位的Windows上的非BMP值),则该行为是实现定义的。

5)多字符常量,例如'AB',具有类型int和实现定义的值。

注意

多字符常量的许多实现使用常量中每个字符的值以big-endian顺序(例如'\1\2\3\4'is 的值)初始化所得整数的连续字节0x01020304

在C ++中,普通字符常量具有类型char,而不是int

与整型常量不同,如果char被签名,则字符常量可能具有负值:在这样的实现上'\xFF'有一个int值为-1

当在#if或#elif的控制表达式中使用时,可以根据源字符集,执行字符集或某些其他实现定义的字符集来解释字符常量。

#include <stddef.h>
#include <stdio.h>
#include <uchar.h>
 
int main (void)
{
    printf("constant    value     \n");
    printf("--------    ----------\n");
 
    // integer character constants,
    int c1='a'; printf("'a':        %#010x\n", c1);
    int c2='

C 语法相关

1.#define directive
2.#elif directive
3.#else directive
4.#endif directive
5.#error directive
6.#if directive
7.#ifdef directive
8.#ifndef directive
9.#include directive
10.#line directive
11.#pragma directive
12.alignas
13.Alternative operators and tokens
14.Analyzability
15.Arithmetic operators
16.Arithmetic types
17.Array declaration
18.Array initialization
19.ASCII Chart
20.Assignment operators
21. types
22.Basic concepts
23.Bit fields
24.break statement
25.C language
26.C Operator Precedence
27.cast operator
28.Comments
29.Comparison operators
30.compound literals
31.Conditional inclusion
32.Conformance
33.const type qualifier
34.Constant expressions
35.continue statement
36.Declarations
37.do-while loop
38.Enumerations
39.Escape sequences
40.Expressions
41.External and tentative definitions
42.File scope
43.floating constant
44.for loop
45.Function declarations
46.Function definitions
47.Functions
48.Generic selection
49.goto statement
50.Identifier
51.if statement
52.Implicit conversions
53.Increment/decrement operators
54.Initialization
55.inline function specifier
56.integer constant
57.Lifetime
58.Logical operators
59.Lookup and name spaces
60.Main function
61.Member access operators
62.Memory model
63.Objects and alignment
64.Order of evaluation
65.Other operators
66.Phases of translation
67.Pointer declaration
68.Preprocessor
69.restrict type qualifier
70.return statement
71.Scalar initialization
72.Scope
73.sizeof operator
74.Statements
75.static assert declaration
76.Static storage duration
77.Storage-class specifiers
78.string literals
79.Struct and union initialization
80.Struct declaration
81.switch statement
82.Thread storage duration
83.Type
84.Type
85.Typedef declaration
86.Undefined behavior
87.Union declaration
88.Value categories
89.Variadic arguments
90.volatile type qualifier
91.while loop
92._Alignof operator
93._Noreturn function specifier
C

C 语言是一门通用计算机编程语言,应用广泛。C 语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。