转义序列
描述
\\n
表示换行符
\\r
表示回车
\\b
表示退格
\\f
表示换页符
\\t
表示水平制表符
只要该值适合您的编译器类型char的范围,就可以使用int值初始化char类型变量。
下面是一个类型为char的算术运算示例:
#include <stdio.h>
int main(void)
{
char letter = 'C';// letter contains the decimal code value 67
可以使用scanf()函数读取单个字符,格式说明符为%c。要使用printf()函数将单个字符写入命令行,请使用格式说明符%c。
#include <stdio.h>
int main(void)
{
char ch = 0;
scanf("%c", &ch);// Read one character
%c转换说明符将变量的内容输出为单个字符。%d说明符将其解释为整数。
#include <stdio.h>
#include <stdio.h>
int main(void)
{
char first = 'A';
char second = 'B';
char last = 'Z';
printf()中的转换说明符始终以%字符开头。 如果要输出%字符,请使用转义序列%%。
对于存储有符号整数的每种类型,都有一个存储无符号整数的相应类型。无符号类型占用与签名类型相同的内存量。每个无符号类型名称都是带有前缀为unsigned关键字的带签名类型名称。下表显示了可以使用的基本无符号整数
有五种基本类型的变量可以存储有符号的整数值,因此可以存储正值和负值。键入整数变量类型的名称。
要声明并初始化long类型变量Big_Number,可以这样写:
#include <stdio.h>
int main(void)
八进制值是基数为8的数字。每个八进制数字的值从0到7,八进制数字使用二进制三位。以零开头的整数常量(如014)将被解释为八进制数。014是十进制值12的八进制等值。
可以以十六进制格式写入整数值,该值以16为基数。十六进制数中的数字相当于十进制值0到15,它们由0到9和A到F(或小写的a到f)表示。十六进制数字用前缀0x或0X写入。
#include <stdio.h>
#include <stdlib.h>
int getval(void);
int main()
{
int age,weight,area;
float iq;
基于8的数字系统称为八进制,使用数字0到7。在八进制中,数字10与十进制中的8相同。基数为16的系统称为十六进制,使用数字0到9加上字母A到F,分别代表10,11,12,13,14和15。
#include<stdio.h>
int main (void)
{
char c, d;
c = 'd';
d = c;
printf ("d = %c\\n", d);
#include <stdio.h>
#include <string.h>
int main()
{
int i;
char msg[] = "yiibai.com";
#include <stdio.h>
#include <string.h>
int main(){
int i;
char msg[25];
printf("Type up to 25 characters and then press Enter...\\n");
#include <stdio.h>
int main()
{
printf("Column A\\tColumn B\\tColumn C");
printf("\\nMy Computer\\'s Beep Sounds Like This: \\a!\\n");
#include <stdio.h>
int main()
{
printf("Quantity\\tCost\\tTotal\\n");
printf("%d\\t\\t$%.2f\\t$%.2f\\n", 3, 9.99, 29.97);
isdigit()函数接受一个参数。
isdigit(x)
如果参数x是一个数字,则isdigit()函数将返回一个true值; 否则,为0或false值。
#include <stdio.h>
int main()
{
char cResponse = '\\0';
printf("Enter the letter A: ");
getch()不会将字符回显到屏幕上。getche()函数与getch()相同,但键是回显的。
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char ch;
printf("Enter some text (type a period to quit).\\n");
#include <stdio.h>
int main()
{
char c;
printf("Please make your treat selection:\\n");
printf("1 - Beverage.\\n");
#include <stdio.h>
int main()
{
char a,b;
printf("Which character is greater?\\n");
printf("Type a single character:");
#include <stdio.h>
int main()
{
char ch;
puts("Start typing");
puts("Press ~ then Enter to stop");
#include <stdio.h>
int main()
{
char num;
printf("Enter a number from 0 to 9:\\n");
num = getchar();
#include <stdio.h>
int main()
{
char key;
puts("Type your favorite keyboard character:");
#include <stdio.h>
int main()
{
puts("Press Enter:");
getchar();
putchar('Y');
putchar('i');