常量

任何基本类型都有变量和常量两种类型。
常量是其值在程序运行期间不能修改,例如小数3.14,字符'a'都是常量,常量之所以不能被修改,是因为常量是在文字常量区。
在存储数据时,考虑到数据不同的用途和特点,把内存存储区域分为各种区域:栈区、堆区、代码区、文字常量区、全局区。每个区域的数据类型都有各自的特点。
在日常开发中常用的常量有字符常量、短整型常量、整型常量、长整型常量、单精度浮点型常量以及双精度浮点型常量。
结合提供的printf函数以及格式符实现格式化输出常用基本数据类型的常量值
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
/*
printf输出常用基本数据类型的常量
@author liuguanglei ittimelinedotnet@gmail.com
@wechat 18601767221
@website ittimeline.net
@version 2019/12/17
*/
int main(int argc, char* argv[])
{
//%c 用于输出一个字符,这里输出字符a 因此完整的输出内容为char c = a
printf("char c = %c n", 'a');
//%hd用于输出短整型
printf("short s = %hd n", 10);
//%d用于输出整型
printf("int i = %d n", 100);
//%ld用于输出长整型
printf("long l = %ld n", 10000);
//%lld用于输出长长整型
printf("long ll = %lld n", 100000000000000000);
//%f用于输出单精度浮点型 3.14后的f表示将3.14当成单精度浮点数处理
printf("float f = %f", 3.14f);
//%ld用于输出双精度浮点型
printf("double d = %lf", 3.14);
system("pause");
return 0;
}胜象大百科 







