实验一:了解数据类型大小和转转义序列的作用

实验内容:1.判断当前系统的指定类型的大小是多少

                  2.掌握部分转义序列的使用

1.判断当前系统的指定类型的大小是多少

实验代码:

# include<stdio.h>
int main()
{
	printf("Type char has a size of %zd bytes.\n", sizeof(char));
	printf("Type short has a size of %zd bytes.\n", sizeof(short));
	printf("Type int has a size of %zd bytes.\n", sizeof(int));
	printf("Type long has a size of %zd bytes.\n", sizeof(long));
	printf("Type long long has a size of %zd bytes.\n", sizeof(long long));
	printf("Type float has a size of %zd bytes.\n", sizeof(float));
	printf("Type double has a size of %zd bytes.\n", sizeof(double));
	printf("Type long double has a size of %zd bytes.\n", sizeof(long double));

	return 0;
}

运行结果:

Type char has a size of 1 bytes.
Type short has a size of 2 bytes.
Type int has a size of 4 bytes.
Type long has a size of 4 bytes.
Type long long has a size of 8 bytes.
Type float has a size of 4 bytes.
Type double has a size of 8 bytes.
Type long double has a size of 8 bytes.

2.掌握部分转义序列的使用

实验代码:

# include<stdio.h>
int main()
{
	float salary;

	printf("\aEnter your desired monthly salary:");
	printf("$_______\b\b\b\b\b\b\b");
	printf(”%d”,scanf("%f", &salary));
	printf("\n\t$%.2f a month is $%.2f a year.", salary,salary*12.0);
	printf("\rWow!\n");

	return 0;
}

运行结果:

Enter your desired monthly salary:$4000.00

Wow!    $4000.00 a month is $48000.00 a year.

总结:

      1. 程序1列出了八种类型的大小

      2. sizeof 是c语言的内置运算符,以自节为单位给出指定类         型的大小

      3. sizeof的返回类型是%zd

      4. 程序2展示了\a \b \t \n \r这几种转义序列的用法

      5. \a的作用为警报;\b的作用为退格;\t为水平制表符;         \n的作用为换行;\r的作用为回车

      6. 只要scanf()读取一个整数,就会返回1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值