编程笔记

  • 字符类型是什么?

    可以通过字符常量为char类型的变量指定初始值。字符常量是在单引号之间写入的字符。看看下面的例子: #include <stdio.h> int main(void) { char letter = 'A'; char digit = '9'; char excl…

    编程笔记 2022年6月7日
  • 在一对单引号之间使用转义序列来指定字符常量

    转义序列 描述 /n 表示换行符 /r 表示回车 /b 表示退格 /f 表示换页符 /t 表示水平制表符 /v 表示一个垂直制表符 /a 插入一个铃(警报)字符 /? 插入问号(?) /" 插入双引号(") /' 插入单引号(') //…

    编程笔记 2022年6月7日
  • 使用整数值初始化char类型的变量

    只要该值适合您的编译器类型char的范围,就可以使用int值初始化char类型变量。 #include <stdio.h> int main(void) { char letter = 74; // ASCII code for the letter J printf("The character is %c/n…

    编程笔记 2022年6月7日
  • 对char类型的值进行算术运算

    下面是一个类型为char的算术运算示例: #include <stdio.h> int main(void) { char letter = 'C'; // letter contains the decimal code value 67 printf("The character is %c/n", letter…

    编程笔记 2022年6月7日
  • 字符输入和字符输出

    可以使用scanf()函数读取单个字符,格式说明符为%c。要使用printf()函数将单个字符写入命令行,请使用格式说明符%c。 #include <stdio.h> int main(void) { char ch = 0; scanf("%c", &ch); …

    编程笔记 2022年6月7日
  • 输出字符的数值

    #include <stdio.h> int main(void) { char ch = 0; scanf("%c", &ch); // Read one character printf("The character is %c/n", ch); printf("The character is %c and the co…

    编程笔记 2022年6月7日
  • 使用转换说明符%c将char类型输出为字符

    %c转换说明符将变量的内容输出为单个字符。%d说明符将其解释为整数。 #include <stdio.h> int main(void) { char first = 'T'; char second = 63; printf("The first example as a letter loo…

    编程笔记 2022年6月7日
  • 将算术运算应用于char类型的值

    #include <stdio.h> int main(void) { char first = 'A'; char second = 'B'; char last = 'Z'; char number = 40; char ex1 = first + 2; // Add 2 to 'A' char ex2 = seco…

    编程笔记 2022年6月7日
  • 使用int类型的变量

    printf()中的转换说明符始终以%字符开头。 如果要输出%字符,请使用转义序列%%。 #include <stdio.h> int main(void) { int salary; // Declare a variable called salary salary = 10000; // Store 10000 …

    编程笔记 2022年6月7日
  • 创建和使用无符号整数类型

    对于存储有符号整数的每种类型,都有一个存储无符号整数的相应类型。无符号类型占用与签名类型相同的内存量。每个无符号类型名称都是带有前缀为unsigned关键字的带签名类型名称。下表显示了可以使用的基本无符号整…

    编程笔记 2022年6月7日