#include<stdio.h>——包含一个叫stdio.h的文件
int main() ——主函数—程序的入口——main函数有且仅有一个
int——整型 return 0——返回 0
printf——打印函数 例:printf("hello,xiaoyang\n");
数据类型
char——字符数据类型
#include<stdio.h>
{
int main
char ch='A';
printf("%c\n",ch); //%c——打印字符格式的数据
}
int——整形
#include<stdio.h>
{
int main
int a=66
printf("%d\n",a); //%d——打印整形十进制数据.
}
short——短整型
long——长整型
long long——更长的整形
float——单精度浮点数
doudle——双精度浮点数
变量的分类
局部变量和全局变量
#include<stdio.h>
int num2 = 20; //——全局变量-定义在代码块外({})的变量
int main()
{
int num1 = 10; //——全局变量-定义在代码块外({})的变量
return 0;
}
当局部变量和全局变量的名字相同时,局部变量优先
作用域
全局变量的作用域是整个工程
局部变量的作用域是变量所在的局部范围
生命周期
全局变量的生命周期是 整个程序的生命周期。
局部变量的生命周期是 进入作用域生命周期开始,出作用域生命周期结束。