C语言入门第三天之变量常量

变量:字面意思是能变化的量

常量:字面意思是不能变化的量

C语言变量定义:

int number = 12;//整型数据定义
number = 13;//✔可以改变
float f = 1.2;//浮点型数据定义
f = 1.3;//✔可以改变
char ch = 'a';//字符型数据定义
ch = 'b';//✔可以改变

C语言常量定义:

const int number = 12;
number = 13;//❌常量不可以改变
const float f = 1.2;
f = 1.3;//❌常量不可以改变
const char ch = 'a';
ch = 'b';//❌常量不可以改变

常量的另一种定义方式:

#define number 12
#include<stdio.h>
#define number 12
int main()
{
	number = 13;//❌常量不能被改变
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/assiduous_me/article/details/82086235