|
|
|
小弟急需一个给文件夹加密码的工具,望大侠快出现!
超级秘密磁盘3000可以的啊 工具斑竹说的那些软件去黑鹰基地找啊,都有破解版的 要是不想让人打开或删除的话,可以直接在命令提示符下 md zyf..\ 然后copy 文件名 zyf..\ 这个文件夹打不开的,也删除不了的 打开的时候再建一个md zyf...\注意这次是三个点,建好了直接打开zyf...\就可以看见zyf..\里的东西,至于原理呢自己想想很简单的哦,与文件夹的路径有关,自己想象就明白了!! 不过这个方法遇上知道的人那就等于没有一样的,呵呵!!! |
|
有没有用命令行加密文件夹的软件?
加密文件夹的目的是什么??? 要是不想让人打开或删除的话,可以直接在命令提示符下 md zyf..\ 然后copy 文件名 zyf..\ 这个文件夹打不开的,也删除不了的 打开的时候再建一个md zyf...\注意这次是三个点,建好了直接打开zyf...\就可以看见zyf..\里的东西,至于原理呢自己想想很简单的哦,与文件夹的路径有关,自己想象就明白了!! 至于exe文件呢?你copy到那个文件夹下也受到了保护啊 !! |
|
[求助]我在看雪下载的w32dsm怎么不能正确显示汉字?乱码了
最初由 kanxue 发布 恩我也用的!! |
|
[分享]VB断点设置心得
我认可3楼的说法!! |
|
|
|
|
|
|
|
[原创]注册机模版1.0 BY 4nil
既然是原创的我也支持下!!! |
|
|
|
|
|
[解释]我对QQ幻想助理捆绑阿拉大盗的解释---请看雪还我公道
现在玩游戏还用外挂啊!! |
|
[求助]用Win32ASM怎样设计出按WinXP形式显示窗口界面
收下了!!!!!!!!!!!! |
|
[求助]如何调用别人的DLL啊?
你要用什么编程工具呢? |
|
|
|
|
|
C语言入门级教程,新手进!!!
下文中的□是空格; 第3章 顺序结构程序设计 为了让计算机处理各种数据,首先就应该把源数据输入到计算机中;计算机处理结束后,再将目标数据信息以人能够识别的方式输出。C语言中的输入输出操作,是由C语言编译系统提供的库函数来实现。 3.1 格式化输出――printf()函数 3.2 格式化输入――scanf()函数 3.3 单个字符输入输出――getchar()和putchar()函数 3.4 顺序结构程序设计 良好的源程序书写风格──顺序程序段左对齐 3.1 格式化输出――printf()函数 printf()函数的作用:向计算机系统默认的输出设备(一般指终端或显示器)输出一个或多个任意类型的数据。 3.1.1 printf()函数的一般格式 [案例3.1] 已知圆半径radius=1.5,求圆周长和圆面积。/*案例代码文件名:AL3_1.C。*/ main() {float radius,length,area,pi=3.1415926; radius=1.5; length=2*pi*radius; /*求圆周长*/ area=pi*radius*radius; /*求圆面积*/ printf(“radius=%f\n”,radius);/*输出圆半径*/ printf(“length=%7.2f,area=%7.2f\n”,length,area); /*输出圆周长、面积*/ } 程序运行结果如下: radius=1.500000 length= 9.42,area= 7.07 printf()函数的一般格式如下: rintf("格式字符串 [,输出项表]); 1.格式字符串。“格式字符串”也称“转换控制字符串”,可以包含三种字符: (1)格式指示符。格式指示符的一般形式如下: %[标志][宽度][.精度][F|N|h|L][类型] 常用的标志字符如表3-1所示,常用的宽度指示符如表3-2所示,常用的精度指示符如表3-3所示,长度修饰符如表3-4所示,类型转换字符如表3-5所示。 (2)转义字符 例如,[案例3.1]中printf()函数中的`\n`就是转义字符,输出时产生一个“换行”操作。 (3)普通字符──除格式指示符和转义字符之外的其它字符。格式字符串中的普通字符,原样输出。 radius);”语句中的“radius=”,“printf("length=%7.2f,area=%7.2f\n, length,area);”语句中的“length=”、“area=”等都是普通字符。 2.输出项表 输出项表是可选的。如果要输出的数据不止1个,相邻2个之间用逗号分开。下面的printf()函数都是合法的: 1)printf("I am a student.\n); 2)printf("%d,3+2); 3)printf("a=%f b=%5d\n, a, a+3); 必须强调:“格式字符串”中的格式指示符,必须与“输出项表”中、输出项的数据类型一致,否则会引起输出错误。 3.1.2 格式指示符 输出不同类型的数据,要使用不同的类型转换字符。 1.类型转换字符d──以带符号的十进制整数形式输出。 [案例3.2] 类型转换字符d的使用。 /*案例代码文件名:AL3_2.C。*/ main() {int num1=123; long num2=123456; /*用3种不同格式,输出int型数据num1的值*/ rintf("num1=%d,num1=%5d,num1=%-5d,num1=%2d\n, num1,num1,num1,num1); /*用3种不同格式,输出long型数据num2的值*/ rintf("num2=%ld,num2=%8ld,num2=%5ld\n,num2,num2,num2); rintf("num1=%ld\n,num1); } 程序运行结果如下: num1=123,num1=□□123,num1=123□□,num1=123 num2=123456,num2=□□123456,num2=123456 num1=16908411 对于整数,还可用八进制、无符号形式(%o(小写字母o))和十六进制、无符号形式(%x)输出。对于unsigned型数据,也可用%u格式符,以十进制、无符号形式输出。 谓无符号形式是指,不论正数还是负数,系统一律当作无符号整数来输出。例如,printf("%d,%o,%x\n,-1,-1,-1); 2.类型转换字符f──以小数形式、按系统默认的宽度,输出单精度和双精度实数。 [案例3.3] 类型转换字符f的使用。 /*案例代码文件名:AL3_3.C。*/ main( ) {float f=123.456; double d1,d2; d1=1111111111111.111111111; d2=2222222222222.222222222; rintf("%f,%12f,%12.2f,%-12.2f,%.2f\n,f,f,f,f,f); rintf("d1+d2=%f\n,d1+d2); } 程序运行结果如下: 123.456001,□□123.456001,□□□□□□123.46,123.46□□□□□□,123.46 d1+d2=3333333333333.333010 本案例程序的输出结果中,数据123.456001和3333333333333.333010中的001和010都是无意义的,因为它们超出了有效数字的范围。 对于实数,也可使用格式符%e,以标准指数形式输出:尾数中的整数部分大于等于1、小于10,小数点占一位,尾数中的小数部分占5位;指数部分占4位(如e-03),其中e占一位,指数符号占一位,指数占2位,共计11位。 也可使用格式符%g,让系统根据数值的大小,自动选择%f或%e格式、且不输出无意义的零。 3.类型转换字符c──输出一个字符(只占一列宽度)。 [案例3.4] 类型转换字符c的使用。 /*案例代码文件名:AL3_4.C。*/ main() {char c=`A`; int i=65; rintf("c=%c,%5c,%d\n,c,c,c); rintf("i=%d,%c,i,i); } 程序运行结果如下: c=A,□□□□A,65 i=65,A 需要强调的是:在C语言中,整数可以用字符形式输出,字符数据也可以用整数形式输出。将整数用字符形式输出时,系统首先求该数与256的余数,然后将余数作为ASCII码,转换成相应的字符输出。 4.类型转换字符s──输出一个字符串。 [案例3.5] 类型转换字符s的使用。 /*案例代码文件名:AL3_10.C。*/ main() "Internet); "Internet); } 程序运行结果如下: Internet,Internet,Internet□□,□□□□□Inter,Inter□□□□□,Inter 注意:系统输出字符和字符串时,不输出单引号和双引号。 3.1.3 使用说明 (1)printf()可以输出常量、变量和表达式的值。但格式控制中的格式说明符,必须按从左到右的顺序,与输出项表中的每个数据一一对应,否则出错。 1.0 / 2.0, 3 + 5, "CHINA);是错误的。 (2)格式字符x、e、g可以用小写字母,也可以用大写字母。使用大写字母时,输出数据中包含的字母也大写。除了x、e、g格式字符外,其它格式字符必须用小写字母。 例如,%f不能写成%F。 (3)格式字符紧跟在“%”后面就作为格式字符,否则将作为普通字符使用(原样输出)。 例如,“printf(”c=%c, f=%f\n“, c, f);”中的第一个c和f,都是普通字符。 3.2 格式化输入――scanf()函数 scanf()函数是用来从外部输入设备向计算机主机输入数据的。 3.2.1 scanf()函数的一般格式 [案例3.6] 已知圆柱体的底半径radius=1.5,高high=2.0,求其体积。/*案例代码文件名:AL3_6.C。*/ main() { float radius=1.5, high=2.0, pi=3.14159, vol; vol=pi*radius*radius*high; /*求体积*/ printf(“vol=%7.2f\n”,vol); /*输出求出的体积*/ } [案例3.7] 已知圆柱体的底半径为radius,高为high,求其体积。 /*案例代码文件名:AL3_7.C。*/ /*功能:说明函数scanf()的格式及作用。*/ main() {float radius,high,vol,pi=3.1415926; rintf("Please input radius & high: ); canf("%f%f,&radius,&high); /*从键盘输入两个实数赋给变量r,h*/ vol=pi*radius*radius*high; rintf("radius=%7.2f, high=%7.2f, vol=%7.2f\n, radius,high,vol); } 程序运行结果如下: Please input radius & high: 1.5□2.0ㄌ radius=□□□1.50,high=□□□2.00,vol=□□14.14 在程序中给计算机提供数据,可以用赋值语句,也可以用输入函数。在C语言中,可使用scanf()函数,通过键盘输入,给计算机同时提供多个、任意的数据。 1. scanf()函数的一般格式 canf("格式字符串, 输入项首地址表); (1)格式字符串。格式字符串可以包含3种类型的字符:格式指示符、空白字符(空格、Tab键和回车键)和非空白字符(又称普通字符)。 格式指示符与printf()函数的相似,空白字符作为相邻2个输入数据的缺省分隔符,非空白字符在输入有效数据时,必须原样一起输入。 (2)输入项首地址表──由若干个输入项首地址组成,相邻2个输入项首地址之间,用逗号分开。 输入项首地址表中的地址,可以是变量的首地址,也可以是字符数组名或指针变量。 变量首地址的表示方法: &变量名 其中“&”是地址运算符。例如,[案例3.7]中的“&radius”是指变量radius在内存中的首地址。 2.scanf()函数的功能:从键盘上接收格式化输入。 运行[案例3.7]的程序时,从键盘上输入2个实数,分别存入&radius、&high起始的存储单元中,即输入两个实数分别赋给radius和high。 3.2.2 格式指示符 格式指示符的一般形式为: % 类型字符如表3-6所示。例如,在[案例3.7]的scanf()函数语句中,格式字符串“%f%f”。 2.宽度n 指定该项输入数据所占列数为n。 换句话说,读取输入数据中相应的n位,但按需要的位数赋给相应的变量,多余部分被舍弃。 如,scanf("%3c%3c,&ch1,&ch2); rintf("ch1=%c,ch2=%c\n,ch1,ch2); 假设输入“abcdefg”,则系统将读取的“abc”中的“a”赋给变量ch1;将读取的“def”中的“d”赋给变量ch2,所以printf()函数的输出结果为:ch1=a,ch2=d 3.赋值抑制字符* 表示本输入项对应的数据读入后,不赋给相应的变量(该变量由下一个格式指示符输入)。 如,scanf("%2d%*2d%3d,&num1,&num2); rintf("num1=%d,num2=%d\n,num1,num2); 假设输入“123456789”,则系统将读取“12”并赋值给num1;读取“34”、但舍弃掉(“*”的作用);读取“567”并赋值给num2。所以,printf()函数的输出结果为:num1=12,num2=567。 4.类型修饰符──F、N、h、l。 其含义与printf()中的一样,分别为远指针、近指针、短整型和长整型。 3.2.3 数据输入操作 1.如果相邻2个格式指示符之间,不指定数据分隔符(如逗号、冒号等),则相应的2个输入数据之间,至少用一个空格分开,或者用Tab键分开,或者输入1个数据后,按回车,然后再输入下1个数据。 如,scanf("%d%d,&num1,&num2); 假设给num1输入12,给num2输入36,则正确的输入操作为:12□36ㄌ 或者:12ㄌ 36ㄌ 注:使用“ㄌ”符号表示按回车键操作,在输入数据操作中的作用是,通知系统输入操作结束。 2.“格式字符串”中出现的普通字符(包括转义字符形式的字符),务必原样输入。 如,scanf("%d,%d,&num1,&num2); 假设给num1输入12,给num2输入36,正确的输入操作为:12,36ㄌ 另外,scanf()函数中、格式字符串内的转义字符(如\n),系统并不把它当转义字符来解释,从而产生一个控制操作,而是将其视为普通字符,所以也要原样输入。 如:scanf("num1=%d,num2=%d\n,&num1,&num2); 假设给num1输入12,给num2输入36,正确的输入操作为: num1=12,num2=36\nㄌ 提高人机交互性建议:为改善人机交互性,同时简化输入操作,在设计输入操作时,一般先用printf()函数输出一个提示信息,再用scanf()函数进行数据输入。 如,将scanf("num1=%d,num2=%d\n,&num1,&num2 );改为: ; scanf("%d,&num1); ; scanf("%d,&num2); 3.输入数据时,遇到以下情况,系统认为该数据结束: (1)遇到空格,或者回车键,或者Tab键。 (2)遇到输入域宽度结束。例如“%3d”,只取3列。 (3)遇到非法输入。例如,在输入数值数据时,遇到字母等非数值符号(数值符号仅由数字字符0-9、小数点和正负号构成)。 4.使用格式说明符“%c”输入单个字符时,空格和转 义字符均作为有效字符被输入。 如,scanf("%c%c%c,&ch1,&ch2,&ch3); rintf("ch1=%c,ch2=%c,ch3=%c\n,ch1,ch2,ch3); 假设输入:A□B□Cㄌ,则系统将字母`A`赋值给ch1,空格`□`赋值给ch2,字母`B`赋值给ch3 3.3 单个字符输入输出――getchar()和putchar()函数 3.3.1 单个字符的输出──putchar()函数 [案例3.8] putchar() 函数的格式和使用方法。 /*案例代码文件名:AL3_8.C*/ /*功能:说明putchar()函数的格式和使用方法。*/ include "stdio.h /*编译预处理命令:文件包含*/ main() {char ch1=`N`, ch2=`E`, ch3=`W`; putchar(ch1); putchar(ch2); putchar(ch3); /*输出*/ putchar(`\n`); putchar(ch1); putchar(`\n`); /*输出ch1的值,并换行*/ putchar(`E`); putchar(`\n`); /*输出字符`E`,并换行*/ putchar(ch3); putchar(`\n`); } 程序运行结果如下: NEW N E W 1.putchar()函数的格式: putchar(ch); 其中ch可以是一个字符变量或常量,也可以是一个转义字符。 2.putchar()函数的作用:向终端输出一个字符。 (1)putchar()函数只能用于单个字符的输出,且一次只能输出一个字符。另外,从功能角度来看,printf()函数可以完全代替putchar()函数。 (2)在程序中使用putchar()函数,务必牢记:在程序(或文件)的开头加上编译预处理命令(也称包含命令),即: include "stdio.h 表示要使用的函数,包含在标准输入输出(stdio)头文件(.h)中。 3.3.2 单个字符的输入──getchar()函数 [案例3.9] 说明getchar()函数的格式和作用。 /*案例代码文件名:AL3_9.C*/ /*功能:说明getchar()函数的格式和作用。*/ include "stdio.h /*文件包含*/ main() {char ch; rintf("Please input two character: ); ch=getchar(); /*输入1个字符并赋给ch */ putchar(ch);putchar(`\n`); putchar(getchar()); /*输入一个字符并输出*/ putchar(`\n`); } 程序运行情况如下: Please input two characters: abㄌ a b 1.getchar()函数的格式:getchar(); 2.getchar()函数的作用:从系统隐含的输入设备(如键盘)输入一个字符。另外,从功能角度来看,scanf()函数可以完全代替getchar()函数。 (1)getchar()函数只能用于单个字符的输入,一次输入一个字符。 (2)程序中要使用getchar()函数,必须在程序(或文件)的开头加上编译预处理命令: #include "stdio.h“ 3.4 顺序结构程序设计 在顺序结构程序中,各语句(或命令)是按照位置的先后次序,顺序执行的,且每个语句都会被执行到。 在顺序结构程序中,一般包括以下几个部分: 1.程序开头的编译预处理命令。 在程序中要使用标准函数(又称库函数),除printf()和scanf()外,其它的都必须使用编译预处理命令,将相应的头文件包含进来。。 2.顺序结构程序的函数体中,是完成具体功能的各个语句和运算,主要包括: (1)变量类型的说明。 (2)提供数据语句。 (3)运算部分。 (4)输出部分。 良 好 的 源 程 序 书 写 风 格──顺序程序段左对齐 顺序程序段中的所有语句(包括说明语句),一律与本顺序程序段的首行左对齐。 |
|
C语言入门级教程,新手进!!!
2章 数据类型、运算符与表达式 2.1 程序设计概述 2.2 C语言的数据类型 2.3 常量和变量 2.4 整型数据 2.5 实型数据 2.6 字符型数据 2.7 算术运算与算术表达式 2.8 赋值运算与赋值表达式 2.9 C语言特有的运算和运算符 2.1 程序设计概述 一个程序应包括对数据的描述和对数据处理的描述。 1.对数据的描述,即数据结构。数据结构是计算机学科的核心课程之一,有许多专门著作论述,本课程就不再赘述。在C语言中,系统提供的数据结构,是以数据类型的形式出现的。 2.对数据处理的描述,即计算机算法。算法是为解决一个问题而采取的方法和步骤,是程序的灵魂。为此,著名计算机科学家沃思(Nikiklaus Wirth)提出一个公式: 数据结构 + 算法 = 程序 实际上,一个程序除了数据结构和算法外,还必须使用一种计算机语言,并采用结构化方法来表示。 2.2 C语言的数据类型 C语言提供的数据结构,是以数据类型形式出现的。具体分类如下: 1.基本类型 分为整型、实型(又称浮点型)、字符型和枚举型四种。 2.构造类型 分为数组类型、结构类型和共用类型三种。 3.指针类型。在第9章中介绍。 4.空类型 C语言中的数据,有常量和变量之分,它们分别属于上述这些类型。 本章将介绍基本类型中的整型、实型和字符型三种数据。 2.3 常量和变量 2.3.1 常量 1.常量的概念 在程序运行过程中,其值不能被改变的量称为常量。 2.常量的分类 (1)整型常量 (2)实型常量 (3)字符常量。 (4)符号常量。 常量的类型,可通过书写形式来判别。 2.3.2 变量 1.变量的概念 在程序运行过程中,其值可以被改变的量称为变量。 2.变量的两个要素 (1)变量名。每个变量都必须有一个名字──变量名,变量命名遵循标识符命名规则。 (2)变量值。在程序运行过程中,变量值存储在内存中。在程序中,通过变量名来引用变量的值。 3.标识符命名规则 (1)有效字符:只能由字母、数字和下划线组成,且以字母或下划线开头。 (2)有效长度:随系统而异,但至少前8个字符有效。如果超长,则超长部分被舍弃。 例如,由于student_name和student_number的前8个字符相同,有的系统认为这两个变量,是一回事而不加区别。 在TC V2.0中,变量名(标识符)的有效长度为1~32个字符,缺省值为32。 (3)C语言的关键字不能用作变量名。 注意:C语言对英文字母的大小敏感,即同一字母的大小写,被认为是两个不同的字符。 习惯上,变量名和函数名中的英文字母用小写,以增加可读性。 思考题:在C语言中,变量名total与变量名TOTAL、ToTaL、tOtAl等是同一个变量吗? 标识符命名的良好习惯──见名知意: 所谓“见名知意”是指,通过变量名就知道变量值的含义。通常应选择能表示数据含义的英文单词(或缩写)作变量名,或汉语拼音字头作变量名。 例如,name/xm(姓名)、***/xb(性别)、age/nl(年龄)、salary/gz(工资)。 4.变量的定义与初始化 在C语言中,要求对所有用到的变量,必须先定义、后使用;且称在定义变量的同时进行赋初值的操作为变量初始化。 (1)变量定义的一般格式 [存储类型] 数据类型 变量名[, 变量名2……]; 例如,float radius, length, area; (2)变量初始化的一般格式 [存储类型] 数据类型 变量名[=初值][, 变量名2[=初值2]……]; 例如,float radius=2.5, length, area; 2.4 整型数据 2.4.1 整型变量 1.分类 根据占用内存字节数的不同,整型变量又分为4类: (1)基本整型(类型关键字为int)。 (2)短整型(类型关键字为short [int])。 (3)长整型(类型关键字为long [int])。 (4)无符号整型。无符号型又分为无符号基本整型(unsigned [int])、无符号短整型(unsigned short)和无符号长整型(unsigned long)三种,只能用来存储无符号整数。 2.占用内存字节数与值域 上述各类型整型变量占用的内存字节数,随系统而异。在16位操作系统中,一般用2字节表示一个int型变量,且long型(4字节)≥int型(2字节)≥short型(2字节)。 显然,不同类型的整型变量,其值域不同。占用内存字节数为n的(有符号)整型变量,其值域为:-2n*8-1~(2n*8-1-1);无符号整型变量的值域为:0~(2n*8-1)。 例如,PC机中的一个int型变量,其值域为-22*8-1~(22*8-1-1),即-32768~32767;一个unsigned型变量的值域为:0~(22*8-1),即0~65535。2.4.2 整型常量 1.三种表示形式 整型常量即整常数,在C语言中可用三种形式表示: (1)十进制。例如10、36。 (2)八进制(以数字0开头)。例如012。 (3)十六进制(以数字0+小写字母x开头)。例如0x36。 2.分类 (1)基本整型。在16位机中,用2字节存储,其数据范围与int型变量一样。 (2)长整型(在数值后面加“L(l)”)。对超出基本整型值域的整型常量,可使用长整型常量表示,其取值范围可达-231-(231-1)。例如,123l、315L等。 3.类型匹配规则 类型匹配规则为:一个整型常量,可以赋给能容纳下其值的整型变量。 例如,其值在-215--(215-1)的整型常量,可以赋给int型变量和long int型变量;其值在-231--(231-1)的整型常量,就只能赋给long int型变量。 注意:常量无unsigned型。但一个非负整型常量,只要它的值不超过相应变量的值域(即取值范围),也可以赋给unsigned型变量 2.5 实型数据 2.5.1 实型变量 C语言的实型变量,分为两种: (1)单精度型。类型关键字为float,一般占4字节(32位)、提供7位有效数字。 (2)双精度型。类型关键字为double,一般占8个字节、提供15~16位有效数字。 2.5.2 实型常量 1.表示形式 实型常量即实数,在C语言中又称浮点数,其值有两种表达形式: (1)十进制形式。例如3.14、9.8。 (2)指数形式:[尾数]E(e)[整型指数]。例如3.0E+5等。 2.关于类型 实型常量不分float型和double型。一个实型常量,可以赋给一个实型变量(float型或double型)。 2.6 字符型数据 2.6.1 字符常量 1.字符常量的定义 用一对单引号括起来的单个字符,称为字符常量。 例如,‘A’、‘1’、‘+’等。 2.转义字符 C语言还允许使用一种特殊形式的字符常量,就是以反斜杠“\ ”开头的转义字符。 注意:如果反斜杠或单引号本身作为字符常量,必须使用转义字符:‘\\’、‘\’‘。 [案例2.1] 用转义字符输出可打印字符和不可打印字符。 /*案例代码文件名:AL2_1.C*//*程序功能:用转义字符输出可打印字符和不可打印字符*/ main() { printf(“\x4F\x4B\x21\n”);/* 等价于printf(“OK\n”);*/ printf(“\x15 \xAB\n”); } 程序运行结果如下: OK! 2.6.2 字符变量 字符变量的类型关键字为char,一般占用1字节内存单元。 1.变量值的存储 字符变量用来存储字符常量。将一个字符常量存储到一个字符变量中,实际上是将该字符的ASCII码值(无符号整数)存储到内存单元中。 例如, char ch1, ch2; /*定义两个字符变量:ch1,ch2*/ ch1=’a’; ch2=’b’; /*给字符变量赋值*/ 2.特性 字符数据在内存中存储的是字符的ASCII码── 一个无符号整数,其形式与整数的存储形式一样(如图2-4所示),所以C语言允许字符型数据与整型数据之间通用。 (1)一个字符型数据,既可以字符形式输出,也可以整数形式输出。 [案例2.2] 字符变量的字符形式输出和整数形式输出。 /*案例代码文件名:AL2_2.C*/ /*程序功能:用字符形式和整数形式输出字符变量*/ main() { char ch1,ch2; ch1=`a`; ch2=`b`; printf(“ch1=%c,ch2=%c\n”,ch1,ch2); printf(“ch1=%d,ch2=%d\n”,ch1,ch2); } 程序运行结果: ch1=a,ch2=b ch1=97,ch2=98 (2)允许对字符数据进行算术运算,此时就是对它们的ASCII码值进行算术运算。 [案例2.3] 字符数据的算术运算。 /*案例代码文件名:AL2_3.C*/ /*程序功能:字符数据的算术运算*/ main() { char ch1,ch2; ch1=‘a’; ch2=‘B’; /*字母的大小写转换*/ printf(“ch1=%c,ch2=%c\n”,ch1-32,ch2+32); /*用字符形式输出一个大于256的数值*/ rintf("ch1+200=%d\n, ch1+200); rintf("ch1+200=%c\n, ch1+200); rintf("ch1+256=%d\n, ch1+256); rintf("ch1+256=%c\n, ch1+256); } 程序运行结果: ch1=A,ch2=b ch1+200=297 ch1+200=) ch1+256=353 ch1+256=a 思考题:用字符形式输出一个大于256的数值,会得到什么结果? 2.6.3 字符串常量 1.字符串常量的概念和字符串长度 字符串常量是用一对双引号括起来的若干字符序列。 字符串中字符的个数称为字符串长度。长度为0的字符串(即一个字符都没有的字符串)称为空串,表示为“ ” (一对紧连的双引号)。 例如,“How do you do.”、“Good morning.”等,都是字符串常量,其长度分别为14和13(空格也是一个字符)。 如果反斜杠和双引号作为字符串中的有效字符,则必须使用转义字符。 如:(1)C:\msdos\v6.22 → "C:\\msdos\\v6.22 y=x--: x=%d,y=%d\n",x,y); } 程序运行结果: x=6 y=++x: x=7,y=7 y=x--: x=6,y=7 思考题:如果将案例“y=++x;”语句中的前置运算改为后置(y=x++;),“y=x--;”语句中的后置运算改为前置(y=--x;),程序运行结果会如何? 3.说明 (1)自增、自减运算,常用于循环语句中,使循环控制变量加(或减)1,以及指针变量中,使指针指向下(或上)一个地址。 (2)自增、自减运算符,不能用于常量和表达式。 例如,5++、--(a+b)等都是非法的。 (3)在表达式中,连续使同一变量进行自增或自减运算时,很容易出错,所以最好避免这种用法。 2.8.2 逗号运算(,)及其表达式 C语言提供一种用逗号运算符“,”连接起来的式子,称为逗号表达式。逗号运算符又称顺序求值运算符。 1.一般形式 表达式1, 表达式2, ……, 表达式n 2.求解过程 自左至右,依次计算各表达式的值,“表达式n” 的值即为整个逗号表达式的值。 例如,逗号表达式“a = 3 * 5, a * 4”的值=60:先求解a = 3 * 5,得a=15;再求a * 4 = 60,所以逗号表达式的值=60。 又例如,逗号表达式“(a = 3 * 5, a * 4), a + 5”的值=20:先求解a = 3 * 5,得a=15;再求a * 4=60;最后求解a + 5=20,所以逗号表达式的值=20。 注意:并不是任何地方出现的逗号,都是逗号运算符。很多情况下,逗号仅用作分隔符。 |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值