C语言变量的定义和声明和常见的5中常量

145 阅读1分钟
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

//变量的定义和声明
//定义:创建变量的时候给初始值
void test2()
{
	int a = 10;
	printf("a=%d\n",a);
}

void test3()
{
	//变量的声明
	//如果变量的定义在变量的使用前,属于自动声明
	//如果变量的定义在使用后,需要显示声明,加关键字extern
	extern int b;//告诉编译器b的定义在后面如果提前使用了,不要报错

	printf("b = %d\n", b);
}
int b = 12;
int main()
{
	test3();
	test2();
	system("pause");
	return 0;
}



#include<stdlib.h>
#include<stdio.h>

#define DAY 7

void test1()
{
	//常见的5种常量
	//1.数值常量100、23、3.14
	//2.字符常量'a','b'
	//3.字符串常量"and"
	//4.符号常量(宏定义)
	printf("一周共有%d\n天",DAY);
	
	//5.const修饰的变量
	const int month = 12;
}

int main()
{
	system("pause");
	return 0;
}