C语言学习笔记:01_基本数据类型
来源:互联网 发布:dnf最新版数据芯片搬砖 编辑:程序博客网 时间:2024/05/01 11:32
/* * 01_基本数据类型.c * * Created on: 2015年7月3日 * Author: zhong */#include <stdio.h>#include <stdlib.h>#include <math.h> //数学#define Pi 3.1415926 //定义符号常量,预编译指令,编译后将由3.1415926代替引用Pi的地方const float pi=3.1415926; //常变量和变量差不多,只是运行期间,数值不能变//整型数据void int_data_type(){printf("-------int------------------\n");signed short a= -10; //signed 有符号的,可以省略,默认是有符号的 ,范围:-2^(2*8-1)--2^(2*8-1)-1 = -2^15-2^15-1 = -32768-32767unsigned short b=-10; //unsigned 无符号的,只能放正数,如果赋予负值,会得到错误的结果,但也可以输出 //范围:0-^2*2*8-1 = 0-2^16-1 = 0-65535long l=10l; //因为long和int都 是4bit,所以不用long l=10L;printf("%d\n",a);printf("%u\n",b); //指定用无符号十进制数的格式输出//sizeof()是测量类型或者变量长度的运算符printf("int=%d\n",sizeof(short)); //2 bitprintf("int=%d\n",sizeof(int)); //4 bitprintf("int=%d\n",sizeof(long)); //4 bitprintf("int=%d\n",sizeof(long long)); //8 bit}//字符型数据 :字符是按其代码(整型)存储的,因此c99将字符型作为整数类型的一种void char_data_type(){printf("-------char----------------\n");printf("char=%d\n",sizeof(char)); //1 bitchar a='a'; //97 0110000001printf("%d %c\n",a,a); //97 aunsigned char c=253;// ? 默认char是有符号的, 0-127printf("%d\n",c);}//浮点型数据:表示具有小数实数 --实数以指数形式存放在存储单元中void float_data_type(){printf("----------float----------------------\n");printf("float=%d ",sizeof(float)); //4bit float能得到6位有效数字printf("double=%d ",sizeof(double)); //8bit double能得到15位有效数字 --c语言中进行浮点数的运算针float型数据自动转换为double型,进行运算printf("long double=%d\n",sizeof(long double)); //12bitfloat f=3.12159f; //表示一个floatdouble a=1.2f; //表示doublelong double d=1.23L;//表示long doubled=1.23l;}//运算符void operational_character(){printf("----运算符---------------------------\n");int a=10;int b=11;printf("%d\n",+a); //- 正号运算符 output:a的值printf("%d\n",-a); //- 负号运算符 output:-10 a的算术负值printf("%d\n",a*a); //* 乘法运算符 output:100printf("%d\n",b/a); // / 除法运算符 output:1 a/b的商 11/10=1 两个整数相除结果为整数float f=11.0f;float g=10.0f;printf("%f\n",f/g); //output:1.100000 两个实数相除结果是双精度实数printf("%d\n",b%a); //% 求余运算符 output:10 10/11=商1余1 a/b的余数 要求参数运算的对象是整数,结果也是整数 8%3=2//除了这个%运算符,其运算符操作数都 可以是任何算术类型printf("%d\n",a+b); //+ 加法运算符printf("%d\n",a-b); //+ 加法运算符//自增运算符 自减运算法 ,只能用于变量,而不能用于常量或者表达式 如:5++,(a+b)++是不合法的//用途:自增减 常用于循环语句,使变量自动加1,也用于指针变量,使指针指向下一地址int i=10;printf("++i=%d\n",++i); //output :11 先增加,后获得值i=10;printf("--i =%d\n",--i); //output :9 先自减,后获得值i=10;printf("i++ =%d\n",i++); //output :10 先获得值,后相加i=10;printf("i-- =%d\n",i--); //output :10 先获得值,后自减}void compute_area(){printf("求三角形的面积 \n");double a,b,c,s,area;a=3;b=4;c=5;s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*(s-c));//开均号函数printf("a=%f,b=%f,c=%f ",a,b,c);printf("area=%f\n",area);}//将秒转换成分种和秒void test(){int count_s=60; //500sif(count_s<60){printf("共%d秒",count_s);}else{int m=count_s/60;int s=count_s%60;printf("共%d分,%d秒",m,s);}}int main1() {//int_data_type();//char_data_type();//float_data_type();//operational_character();//compute_area();test();//system("pause");}
0 0
- C语言学习笔记:01_基本数据类型
- C语言学习笔记之基本数据类型
- 【笔记-C语言】 基本数据类型
- Linux C 学习笔记01-基本数据类型
- C语言深度剖析学习笔记-基本数据类型
- C语言学习笔记 数据类型
- 学习笔记---C语言数据类型
- 01-C语言基本数据类型
- android ndk 01 c语言 基本数据类型_输入输出_指针
- C语言笔记系列(二)--基本数据类型
- c语言笔记——基本数据类型
- 【C语言学习】01__基本数据类型分析
- Go语言学习笔记之基本数据类型
- 黑马程序员—C语言_基本数据类型
- Objective-c语言_基本数据类型封装和拆包
- Objective-C语言_基本数据类型封装和拆包
- c语言-数据类型-基本数据类型
- C语言基本数据类型
- AJAX POST&跨域 解决方案 - CORS
- iOS面试题(3)----内存管理
- JS实现增删改查
- Unix Network 1
- python时间操作
- C语言学习笔记:01_基本数据类型
- Peer To Peer——对等网络
- UVA - 12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)
- C语言学习笔记:02_输入输出函数
- MySQL学习笔记(三):order by排序问题
- 挖坑,把自己埋了两天(我与MySQL的抓狂事)
- Unity 3D酷跑游戏中遇到的问题
- C语言学习笔记:04_选择结构
- WinForm中如何实现嵌入form窗体(panel与子窗体)