局部变量与全局变量

#include <stdio.h>

int main()
{
	int i = 520;
	printf("before, i = %d\n", i);
	for (int i = 0; i < 10; i++)
	{
		printf("%d\n", i);
	}
	printf("after, i = %d\n", i);

	return 0;
}
#include <stdio.h>

void a();
void b();
void c();

int count;

void a()
{
    count++;
}

void b()
{
    count++;
}

void c()
{
    count++;
}

int main()
{
    a();
    b();
    c();
    b();    

    printf("被包了%d次\n", count);

    return 0;
}
View Code
#include <stdio.h>

void func();

int a, b = 520;

void func()
{
	int b;

	a = 880;
	b = 120;

	printf("In func, a = %d, b = %d\n", a, b);
}

int main()
{
	printf("In main, a = %d, b = %d\n", a, b);
	func();
	printf("In main, a = %d, b = %d\n", a, b);

	return 0;
}

extern关键字报错;

#include <stdio.h>

void func();

void func()
{
	extern count;
	count++;
}

int count = 0;

int main()
{
	func();

	printf("%d\n", count);

	return 0;
}

 

posted @ 2019-07-08 13:22  Hello_World2020  阅读(171)  评论(0编辑  收藏  举报