๋”ฐ๋ฐฐ์”จ

๋”ฐ๋ฐฐ์”จ 11.10 ~

์•„์˜ณ์ด 2021. 1. 28. 19:07

11.10 ๋ช…๋ น์ค„ ์ธ์ˆ˜ Command-Line Arguments

-๋ช…๋ น์ค„ ์ธ์ˆ˜๋Š” ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ์‹œ์— argument๋กœ ๋„ฃ์–ด์ค„ ์ˆ˜ ์žˆ๋‹ค.

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(int argc, char * argv[])
{
	int count;

	printf("The command line has %d arguments:\n", argc);

	for (count = 0; count < argc; count++)
		printf("Arg %d : %s\n", count, argv[count]);
	printf("\n");

	return 0;
}

๋ช…๋ น์ค„ ์ธ์ˆ˜๋กœ์„œ ๋ฌธ์ž์—ด์˜ ๋ฐฐ์—ด์„ argv[]์— ๋ฐ›์•„๋“ค์ด๊ณ  ๋ฐฐ์—ด์˜ ๊ฐœ์ˆ˜๋ฅผ argc๋กœ ๋ฐ˜ํ™˜ํ•˜๋Š” ์ฝ”๋“œ

 

 

11.11 ๋ฌธ์ž์—ด์„ ์ˆซ์ž๋กœ ๋ฐ”๊พธ๋Š” ๋ฐฉ๋ฒ•๋“ค

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

int main(int argc, char * argv[])
{
	/*
		string to integer, double, long
		atoi(), atof(), atol()
	*/

	if (argc < 3)
		printf("Wrong usage of %s\n", argv[0]);		//	๋ฐฐ์—ด์˜ 1๋ฒˆ์งธ ๋ฉ”๋ชจ๋ฆฌ๋Š” ์‹คํ–‰ํŒŒ์ผ๋ช…
	else 
	{
		//	Example 1

		int times = atoi(argv[1]);	// ๋ฐฐ์—ด์˜ 2๋ฒˆ์งธ ๋ฌธ์ž์—ด์„ ์ •์ˆ˜๋กœ ๋ฐ”๊ฟ” times์— ๋Œ€์ž…
		//	atof(), atol()

		for (int i = 0; i < times; i++)
			puts(argv[2]);	// ๋ฐฐ์—ด์˜ 3๋ฒˆ์งธ ๋ฌธ์ž์—ด์„ times์— ๋“ค์–ด์˜จ ์ •์ˆ˜๋งŒํผ ์ถœ๋ ฅ

		//Example 2

		printf("Sum = %d\n", atoi(argv[1] + atoi(argv[2])));
	}

	/*
		string to long, unsigned long, double
		strtol(), strtoul(), strtod()

		strtod() converts base 10 only
	*/

	char str1[] = "1024Hello";
	char* end;
	long l = strtol(str1, &end, 10);	//	&end ์ด์ค‘ํฌ์ธํ„ฐ, 10 ์‹ญ์ง„์ˆ˜
	printf("%s %ld %s %d\n", str1, l, end, (int)*end);
	// %s str1 : ๋ณ€ํ™˜ํ•˜๋ ค๋Š” ๋ฌธ์ž์—ด
    // %ld l : ์ˆซ์ž ๋ถ€๋ถ„๋งŒ
    // %s end : strtol ์—์„œ ๋ฌธ์ž์—ด์„ ์ˆซ์ž๋กœ ๋ฐ”๊พธ๋‹ค๊ฐ€ ๋ณ€ํ™”ํ•  ์ˆ˜ ์—†๋Š” ์œ„์น˜์— ์˜ค๋ฉด ๊ทธ ํฌ์ธํ„ฐ๋ฅผ end์— ๋„ฃ์–ด์คŒ
    // %d (int)* end : 'H'์— ํ•ด๋‹นํ•˜๋Š” ์•„์Šคํ‚ค์ˆซ์ž
	char str2[] = "10FFHello";
	l = strtol(str2, &end, 16);
	printf("%s %ld %s %d\n", str2, l, end, (int)* end);
	
	/*
		Numvers to strings
		Use strintf() instead of itoa(), ftoa()
	*/
	
	char temp[100];
	puts(_itoa(10, temp, 16));		//	๊ถŒ์žฅํ•˜์ง€ ์•Š์Œ
	sprintf(temp, "%x", 10);	//a	//printfํ•  ๋‚ด์šฉ์„ ์ „๋ถ€ ๋ฌธ์ž์—ด์— ์ €์žฅ ์ˆซ์ž 10์„ 16์ง„์ˆ˜(%x)๋ฌธ์ž๋กœ
	puts(temp);	
	
	return 0;
}

 

 

12.1 ๋ฉ”๋ชจ๋ฆฌ ๋ ˆ์ด์•„์›ƒ ํ›‘์–ด๋ณด๊ธฐ

-Text Segment : ์ฝ”๋“œ ์„ธ๊ทธ๋จผํŠธ(๊ธฐ๊ณ„์–ด๋กœ ๋ณ€ํ™˜๋œ ์ฝ”๋“œ)

-Data Segment : ์ดˆ๊ธฐํ™”๋œ ์ „์—ญ,์ •์ ๋ณ€์ˆ˜ ์“ฐ๊ธฐ ๊ฐ€๋Šฅ (์—ฌ๊ธฐ ์ €์žฅ๋œ ๋ฌธ์ž์—ด์€ Read Only Data Segment์— ์ €์žฅ๋จ)

-BBS Segment : ์ดˆ๊ธฐํ™” ๋˜์ง€ ์•Š์€ ์ „์—ญ, ์ •์  ๋ณ€์ˆ˜

-Heap : ๋™์  ํ• ๋‹น

-Stack : ์ง€์—ญ๋ณ€์ˆ˜, ๋งค๊ฐœ๋ณ€์ˆ˜

- Text Segment: ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ์‹œ ํ”„๋กœ๊ทธ๋žจ ์ž์ฒด๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ผ๊ฐ€๊ณ  ๋ณ€๊ฒฝ ๋ถˆ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋œ๋‹ค

 

-char* str = "Hello, world"; ์—์„œ ๋ฌธ์ž์—ด Hello, World๋Š” Date Segment์ค‘ Read Only Data Segment์— ์ €์žฅ๋จ

๋”ฐ๋ผ์„œ ํฌ์ธํ„ฐ๋ฅผ ํ†ตํ•ด str[0] = 'M';์€ ์—๋Ÿฌ๋ฅผ ์ผ์œผํ‚จ๋‹ค. ํ•˜์ง€๋งŒ arr์˜ ๊ฒฝ์šฐ stack ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ€๋Šฅํ•˜๋‹ค

 

- ์–ด๋–ค ๋ณ€์ˆ˜๋“ค์€ ํ”„๋กœ๊ทธ๋žจ ์ „์ฒด์—์„œ ๊ณ„์† ์‚ฌ์šฉ๋œ๋‹ค. ์ด๋Ÿฌํ•œ ์ „์—ญ ๋ณ€์ˆ˜๋Š” BBS Segment, Data Segment์— ์ €์žฅ๋œ๋‹ค

 

-์ง€์—ญ์ ์œผ๋กœ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ง€์—ญ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ”๋ชจ๋ฆฌ ํšจ์œจ์ด ์ข‹์•„์ง„๋‹ค ์ด๋Ÿฌํ•œ ์ง€์—ญ๋ณ€์ˆ˜๋Š” ์Šคํƒ ๋ฉ”๋ชจ๋ฆฌ์— ์Œ“์ธ๋‹ค

๋ธ”๋ก ์•ˆ์ด ์‹คํ–‰๋  ๋•Œ๋งŒ stack ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ง€์—ญ๋ณ€์ˆ˜๋ฅผ ์“ฐ๊ณ , ๊ทธ ์™ธ์—” ์“ฐ์ง€ ์•Š๋Š”๋‹ค

์Šคํƒ ๋ฉ”๋ชจ๋ฆฌ์˜ ํŠน์ง• ์ค‘ ํ•˜๋‚˜๊ฐ€ ์ง€์—ญ๋ณ€์ˆ˜๋Š” ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ์‹คํ–‰ ์‹œ์— ์ด๋ฏธ ๋ชจ๋‘ ์ •ํ•ด์ง„๋‹ค. ๋”ฐ๋ผ์„œ ์Šคํƒ ๋ฉ”๋ชจ๋ฆฌ๋Š” ์ ‘๊ทผ์ด ๋น ๋ฅด๋‹ค. ํ•˜์ง€๋งŒ ํ•„์š”ํ•œ ๋ฉ”๋ชจ๋ฆฌ์˜ ํฌ๊ธฐ๋ฅผ ๋ฏธ๋ฆฌ ์•Œ ์ˆ˜ ์—†์„ ๊ฒฝ์šฐ์—” ์Šคํƒ ๋ฉ”๋ชจ๋ฆฌ์— ๋‹ด์„ ์ˆ˜ ์—†๋‹ค.

 

-์ด๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋™์ ํ• ๋‹น ์ด๋ผ๊ณ  ํ•œ๋‹ค(Heap ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ) Heap ๋ฉ”๋ชจ๋ฆฌ๋Š” ์ปดํŒŒ์ผํ•  ๋•Œ๋„ ์‚ฌ์ด์ฆˆ๋ฅผ ์•Œ ์ˆ˜๊ฐ€ ์—†๋‹ค.

๋‹จ์ ์€ ์ฃผ์†Œ๋ฅผ ๋ฐฐ์ •๋ฐ›์„ ๋•Œ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์–ผ๋งˆ๋‚˜ ํ•„์š”ํ•œ์ง€ ์šด์˜์ฒด์ œ์— ์š”์ฒญํ•˜๊ณ  ๋ฐ›์•„์˜ค๋Š” ๊ตฌ์กฐ์ด๊ธฐ ๋•Œ๋ฌธ์— ์กฐ๊ธˆ ๋А๋ฆฌ๋‹ค

๋˜ํ•œ Heap์˜ ๋ฉ”๋ชจ๋ฆฌ๋Š” ๋‹ค ์“ฐ๊ผฌ ๊ผญ ๋ฐ˜๋‚ฉ์„ ํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— free(arr) ๋“ฑ์„ ์จ์„œ, ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋ฐ˜๋‚ฉํ•œ๋‹ค.

 

 

12.2 ๊ฐ์ฒด(object)์™€ ์‹๋ณ„์ž(identifier), L-value์™€ R-value

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	/*
		Object
		- "An object is simply a block of memory that can store a value."
		- Object has more developed meaning in C++ and Object Oriented Programing (OOP)

		Identifiers
		- Names for variables, functions, macros, and other entities
	*/

	int var_name = 3;		// ceates an object called 'var_name'

	int* pt = &var_name;	//	pt is an identifier		ํฌ์ธํ„ฐ๋ณ€์ˆ˜ ์ž์ฒด๋„ ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง
	*pt = 1;				// *pt is not an identifier. *pt designates an object

	int arr[100];	// arr is an identifier. Is arr an object?
    				// ๋ฐฐ์—ด๋ช…์€ ์‹๋ณ„์ž๋Š” ๋งž์ง€๋งŒ, object๋Š” ์•„๋‹ˆ๋‹ค - ์ฒซ์›์†Œ์— ๋Œ€ํ•œ ์ฃผ์†Œ์ด์ง€ ๊ทธ ์ž์ฒด๊ฐ€ ๋ฉ”๋ชจ๋ฅด๋ฆด ๊ฐ–์ง€ ์•Š๋Š”๋‹ค
	arr[0] = 7;		//	arr[0] is an object

	/*
		Lvalue is an expression 'referring' to an object.

		L-value : left side of an assignment
		R-vlaue : right side, variable, constant, expressions
	*/

	var_name = 3;	//	modifiable lvalue
	int temp = var_name;	// Lvalue๊ฐ€ Rvalue๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ณ  ์ด๋•Œ๋Š” ๋‹จ์ˆœํžˆ ๊ฐ’์„ ์ „๋‹ฌํ•˜๋Š” ์—ญํ• 

	pt = &var_name;
	int* ptr = arr;
	*pt = 7;	// *pt is not an identifier but an modifiable lvalue expression

	int* ptr2 = arr + 2 * var_name;	// address rvalue
	*(arr + 2 * var_name) = 456;	// lvalue expression

	const char* str = "Constant string";		// str is a modifiable lvalue
	str = "Second string";	// "Constant string" = "Second string"	//	impossible
	//str[0] = 'A';	// Error
	//puts(str);

	char str2[] = "String in an array";
	str2[0] = 'A';	// OK
	//puts(str2);

	return 0;
}

 

 

12.3 ๋ณ€์ˆ˜์˜ ์˜์—ญ(scope)๊ณผ ์—ฐ๊ฒฐ(Linkage) ์ƒํƒœ, ๊ฐ์ฒด์˜ ์ง€์†๊ธฐ๊ฐ„(duration)

 

Scope

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

/*
	Variable scopes (visibility)
	- block, function, fuction prototype, file
*/

int g_i = 123;	// global variable
int g_j;

void func1()
{
	g_i++;	// uses g_i
}

void func2()
{
	g_i += 2;
} 

int main()
{
	int local = 1234;

	func1();
	func2();

	printf("%d\n", g_i);// uses g_i
	printf("%d\n", g_j);// Not initialized?	//	0	์ดˆ๊ธฐํ™” ๋˜์ง€ ์•Š์€ ์ „์—ญ๋ณ€์ˆ˜๋Š” ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ 0์œผ๋กœ  ์ดˆ๊ธฐํ™”
	printf("%d\n", local);
	
	return 0;
}

1. block { } : { } ์•ˆ์— ์„ ์–ธ๋œ ๋ณ€์ˆ˜๋Š” { } ์•ˆ์—์„œ๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅ

2. function : ํ•จ์ˆ˜ ์•ˆ์—์„œ ์„ ์–ธ๋œ ๋ณ€์ˆ˜์˜ ์˜์—ญ์€ ํ•จ์ˆ˜์•ˆ

3. function prototype : ํ”„๋กœํ† ํƒ€์ž…์˜ ๊ฒฝ์šฐ ํ”„๋กœํ†  ํƒ€์ž… ๋‚ด์—์„œ๋งŒ visibility. (๋”ฐ๋ผ์„œ ์ž๋ฃŒ ํ˜•๋งŒ ์“ฐ๊ณ  ๋ณ€์ˆ˜ ์ƒ๋žต ๊ฐ€๋Šฅ)

4. file scope: ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐ”๊นฅ ๋ถ€๋ถ„(ex. ์ „์—ญ๋ณ€์ˆ˜) - ์—ฌ๊ธฐ์— ์žˆ๋Š” ๋ณ€์ˆ˜๋Š” ํŒŒ์ผ ์•ˆ์—์„œ ์–ด๋””๋“ ์ง€ ์‚ฌ์šฉ

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

/*
	Variable scopes (visibility)
	- block, function, fuction prototype, file
*/

void f1(int hello, double world);	// to the end of the prototype declaration
//void vla_param(int n, int m, double ar[n][m]);	//	gcc only

double func_block(double d)
{
	double p = 0.0;

	int i;
	for (i = 0; i < 10; i++)
		//for (int i = 0; i < 10; i++)
	{
		double q = d * i;
		p *= q;

		if (i == 5)
			goto hello;
	}
hello:
	printf("Hello, World");

	return p;
}

int main()
{
	func_block(1.0);
}

void f1(int hello, double world)
{
}

 

Linkage

ํ•œ ํ”„๋กœ์ ํŠธ ์•ˆ์˜ ๋‘ ๊ฐœ์˜ ํŒŒ์ผ์„ Linkage๋ฅผ ํ†ตํ•ด ์„œ๋กœ ๋ณ€์ˆ˜๋ฅผ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋‹ค.

์˜ค๋ฅธ์ชฝ 3๋ฒˆ์งธ ์ค„์— int el;์— extern์„ ๋ถ™์ด๋ฉด '์–ด๋”˜๊ฐ€ ์„ ์–ธ๋˜์–ด ์žˆ๋Š” int el์„ ์จ๋ผ' ๋ž€ ์˜๋ฏธ์ด๋‹ค.

๋ฐ˜๋ฉด ์™ผ์ชฝ 15๋ฒˆ์งธ ์ค„์— static int il;์€ 'int il;์„ ์กด์žฌํ•˜๋Š” scope ๋‚ด์—์„œ๋งŒ ์กด์žฌํ•œ๋‹ค'๋Š” ์˜๋ฏธ์ด๋‹ค

 

์™ผ์ชฝ 17๋ฒˆ์งธ ์ค„์—์„œ void testLinkage(); ๋ฅผ ๋ณด๋ฉด ํ”„๋กœํ† ํƒ€์ž…์„ ์จ์„œ ๋‹ค๋ฅธ ํŒŒ์ผ์˜ ํ•จ์ˆ˜๋ฅผ ์“ธ ์ˆ˜ ์žˆ๋‹ค.

 

Duration

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

/*
	Storage duration:
	- static storageduration	//	ํ”„๋กœ๊ทธ๋žจ์ด ์‹œ์ž‘๋ ๋•Œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์žก๊ณ  ๋๋‚ ๋•Œ๊นŒ์ง€ ์œ ์ง€
	(Note: 'static' keyword indicates the linkage type, not the storage duration)
	- automatoc storage duration	//	stack์— ์ €์žฅ, ์ง€์—ญ๋ณ€์ˆ˜
	- allocated storage duration	//	๋™์ ํ• ๋‹น
	- thread storage duration		//	๋ฉ€ํ‹ฐ์“ฐ๋ ˆ๋”ฉ
*/

void count()
{
	int ct = 0;	//	ํ˜„์žฌ block ์•ˆ์—์„œ ๋
	printf("count = %d\n", ct);
	ct++;
}

void static_count()
{
	static int ct = 0;	//	ํ”„๋กœ๊ทธ๋žจ์ด ์‹œ์ž‘๋ ๋•Œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์žก๊ณ  ๋๋‚ ๋•Œ๊นŒ์ง€ ์œ ์ง€
	printf("static count = %d\n", ct);
	ct++;
}

int main()
{
	count();			//	0
	count();			//	0
	static_count();		//	0
	static_count();		//	1

	return 0;
}

 

 

12.4 ์ €์žฅ ๊ณต๊ฐ„์˜ ๋‹ค์„ฏ ๊ฐ€์ง€ ๋ถ„๋ฅ˜

2๊ฐ€์ง€๋กœ ๋ถ„๋ฅ˜ํ•˜๊ธฐ๋„ ํ•œ๋‹ค (static๊ณผ static์ด ์•„๋‹Œ ๊ฒƒ)

 

์ž๋™๋ณ€์ˆ˜ : ์ง€์—ญ๋ณ€์ˆ˜ - ์ง€์† ๊ธฐ๊ฐ„์ด ์ž๋™์ ์œผ๋กœ ๊ฒฐ์ •

๋ ˆ์ง€์Šคํ„ฐ๋ณ€์ˆ˜ : CPU ์•ˆ์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์“ฐ๋Š” ๊ฒƒ์œผ๋กœ ์—„์ฒญ ๋น ๋ฆ„ - ์‹ค์งˆ์ ์œผ๋กœ ๋งŽ์ด ์•ˆ ์“ฐ์ธ๋‹ค

Static : ๋ฉ”๋ชจ๋ฆฌ์— ๊ณ ์ •๋˜์–ด ์žˆ๋‹ค (์ปดํŒŒ์ผ๋Ÿฌ์˜ ๋ฒˆ์—ญ๋‹จ์œ„: ํŒŒ์ผ)

 

ํ• ๋‹น๋ฉ”๋ชจ๋ฆฌ : ๋Ÿฐํƒ€์ž„์—์„œ ์šด์˜์ฒด์ œ์—๊ฒŒ ์š”์ฒญํ•ด์„œ 'ํฌ์ธํ„ฐ'๋งŒ ๋ฐ›๋Š”๋‹ค. ์ฆ‰, ์‹๋ณ„์ž๊ฐ€ ์—†๋‹ค

 

 

12.5 ์ž๋™๋ณ€์ˆ˜ Automatic Variables

19๋ฒˆ์งธ ์ค„์—์„œ ์Šคํƒ์— int b = 123 ์ด ์Œ“์˜€๋‹ค๊ฐ€

21๋ฒˆ์งธ ์ค„์—์„œ scope๋ฅผ ๋น ์ ธ๋‚˜์˜ค๋ฉฐ ์Šคํƒ์—์„œ ๋น ์ง€๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

/*
	Automatic storage class
	- Automatic storage duration, block scope, no linkage
	- Any variable declared in a block or function header
*/

void func(int k);

int main()	//Note: main() is a function.
{
	auto int a;	// keyword auto : a storage-class specifier
	a = 1024;
	//printf("%d\n", a);		// whaat happens if uninitialized?
	//auto int b = a * 3;		// whaat happens if uninitialized?
	// bss ์— ์žˆ๋Š” ๋ณ€์ˆ˜๋“ค์€ ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ์•Œ์•„์„œ 0์œผ๋กœ ์ดˆ๊ธฐํ™” ์‹œ์ผœ์ฃผ์ง€๋งŒ, 
	// ์ž๋™๋ณ€์ˆ˜๋Š” ์Šคํƒ์— ์ƒ์„ฑ๋ ๋•Œ๋งˆ๋‹ค ์ดˆ๊ธฐํ™”ํ•ด์ฃผ๋ฉด "๋น„์šฉ"์ด ๋ฐœ์ƒํ•˜๋ฏ€๋กœ ๋ณ„๋„๋กœ ์ดˆ๊ธฐํ™” ์•ˆ์‹œ์ผœ์คŒ
	// ๋”ฐ๋ผ์„œ "์ž๋™๋ณ€์ˆ˜๋Š” ๋ฐ˜๋“œ์‹œ ์ดˆ๊ธฐํ™” ์‹œ์ผœ์ค˜์•ผํ•จ"(c++ ์—์„œ๋Š” ์ด๋Ÿฐ ๋ถˆํŽธํ•จ์„ ๋œ๋А๋ผ๋„๋ก ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์žฅ์น˜๊ฐ€ ๋˜์žˆ๋‹ค๊ณ ํ•จ
	
	int i = 1;
	int j = 2;

	printf("i %lld\n", (long long)&i);

	{
		int i = 3;	//name hiding
		printf("i %lld", (long long)&i);

		int ii = 123;

		// j is visible here
		printf("j = %d\n", j);
	}

	// ii is not visible here

	printf("i %lld\n", (long long)&i);	// which i?

	for (int m = 1; m < 2; m++)
		printf("m %lld\n", (long long)&m);		// no block?

	func(5);	// cannot see any of the variabled defined so far

	for (int m = 3; m < 4; m++)
	{
		printf("m%lld\n", (long long)&m);		// block?
	}

	return 0;
}

void func(int k)// stack frame ์ด ๋ฐ”๊ปด์„œ mainํ•จ์ˆ˜์—์„œ ์“ฐ๋˜ ๋ณ€์ˆ˜๋“ค์— ์ ‘๊ทผํ•  ์ˆ˜ ์—†๋‹ค
{
	int i = k + 2;
	// do something with i and k
	printf("i %lld\n", (long long)&i);
}