全局变量的寿命周期是整个程序;
局部变量的寿命周期是在当前的代码块;
#include<stdio.h> int num1 = 100;//全局变量 int main() { ?? ? ?? ?int age = 20; ?? ?int sum = 0; ?? ?int num1 = 100; ?? ?int num2 = 200; ?? ?char ch = 'A'; ?? ?printf("%c\n", ch);//%C--打印字符格式的数据 ?? ?printf("%d\n", age); ?? ?//short int-d短整型
?? ?printf("%d\n", sizeof(char)); ?? ?printf("%d\n", sizeof(short)); ?? ?printf("%d\n", sizeof(int)); ?? ?printf("%d\n", sizeof(long)); ?? ?printf("%d\n", sizeof(long long)); ?? ?printf("%d\n", sizeof(float)); ?? ?printf("%d\n", sizeof(double)); ?? ? ?? ?scanf_s("%d%d", &num1, &num2);//输入num1num2 ?? ? ?? ?sum = num1 + num2; ?? ?printf("sum=%d\n", sum);
?? ?return 0; }
|