diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8d3a3fd --- /dev/null +++ b/.editorconfig @@ -0,0 +1,2 @@ +[*.c] +charset = utf-8 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bc46f2c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*/* +Computer-Programming-and-Practice-2025-1.vcxproj.user diff --git a/Project-Function-Declarations-With-Parameter-List.vcxproj b/Project-Function-Declarations-With-Parameter-List.vcxproj new file mode 100644 index 0000000..c488cf4 --- /dev/null +++ b/Project-Function-Declarations-With-Parameter-List.vcxproj @@ -0,0 +1,51 @@ + + + + + Debug + x64 + + + + 17.0 + Win32Proj + {56298b6a-7bcc-4ad5-857c-3ae51b8ca9fa} + ProjectFunctionDeclarationsWithParameterList + 10.0 + + + + Application + true + v143 + Unicode + + + + + + + + + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + /utf-8 %(AdditionalOptions) + + + Console + true + + + + + + + + + diff --git a/Project-Function-Declarations-With-Parameter-List.vcxproj.filters b/Project-Function-Declarations-With-Parameter-List.vcxproj.filters new file mode 100644 index 0000000..15aa408 --- /dev/null +++ b/Project-Function-Declarations-With-Parameter-List.vcxproj.filters @@ -0,0 +1,14 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + c + + + + + c 소스 파일 + + + diff --git a/Project-Function-Declarations-With-Parameter-List.vcxproj.user b/Project-Function-Declarations-With-Parameter-List.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/Project-Function-Declarations-With-Parameter-List.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/README.md b/README.md index bb3e4ff..967e275 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,44 @@ -# Computer Programming and Practice 2025-1 - 컴퓨터 프로그래밍 및 실습 과목의 수업 홈페이지 +# 함수선언 (매개변수리스트가 있을 때) + +매개변수는 함수가 호출될 때마다 메모리 공간을 새로 할당받고 함수 실행을 종료할 때 삭제됩니다. +매개변수의 초기값은 호출할 때 정한 값입니다. +함수 선언은 함수의 이름, 반환타입, 매개변수의 타입을 정합니다. +함수 선언시 매개변수의 이름은 적지 않고 타입만 적어도 됩니다. +매개변수가 없는 함수를 선언할 때는 괄호 안에 void만 적습니다. + +`타입` `이름` `(` `매개변수리스트` `)` `;` 형태로 함수선언을 합니다. + +`매개변수리스트`는 `매개변수선언` 또는 `매개변수리스트` `,` `매개변수선언` 입니다. + +`매개변수선언`은 `타입` `이름` 또는 `타입` 입니다. + +#### 코드 예시: +```c +int f(int, int); /* 반환 타입이 int고, 이름이 f고, 매개변수 두개의 타입이 모두 int인 함수의 선언 */ +int g(int a, int b); /* 이름이 g고, 함수 종류는 f와 동일한 함수의 선언 */ +int h(void); /* 반환 타입이 int고, 이름이 h고, 매개변수가 없는 함수의 선언 */ +int x(); /* 반환 타입이 int고, 이름이 x고, 매개변수에 대해서는 정하지 않은 함수의 선언 */ +``` + +#### 관련 C 표준 +3.5.4.3 Function declarators (including prototypes) +> Semantics +> +> A parameter type list specifies the types of, and may declare identifiers for, the parameters of the function. +> ... The special case of void as the only item in the list specifies that the function has no parameters. + +3.5 DECLARATIONS +> Constraints +> +> All declarations in the same scope that refer to the same object or function shall specify compatible types. + +3.5.4.3 Function declarators (including prototypes) +> Semantics +> +> For two function types to be compatible, both shall specify compatible retury types. +> Moreover, the paremeter type lists, ... , shall agree in the number of parameters ... ; +> corresponding parameters shall have compatible types. ... + +1.6 DEFINITION OF TERMS +> Parameter --- an object declared as part of a function declaration or definition +> that acquires a value on entry to the function, or ... diff --git a/Solution-Week2.sln b/Solution-Week2.sln new file mode 100644 index 0000000..73b8a98 --- /dev/null +++ b/Solution-Week2.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35818.85 d17.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project-Function-Declarations-With-Parameter-List", "Project-Function-Declarations-With-Parameter-List.vcxproj", "{56298B6A-7BCC-4AD5-857C-3AE51B8CA9FA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {56298B6A-7BCC-4AD5-857C-3AE51B8CA9FA}.Debug|x64.ActiveCfg = Debug|x64 + {56298B6A-7BCC-4AD5-857C-3AE51B8CA9FA}.Debug|x64.Build.0 = Debug|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7548D284-3031-4A53-8359-876BE48586E0} + EndGlobalSection +EndGlobal diff --git a/main.c b/main.c new file mode 100644 index 0000000..dcbbbc1 --- /dev/null +++ b/main.c @@ -0,0 +1,27 @@ +/* 매개변수리스트가 있는 함수 선언 */ + +/* 문법 + * 함수 선언에서 매개변수 정보를 쓰려면 함수의반환타입 함수이름 ( 매개변수타입 매개변수이름 ) ; 형식으로 선언합니다. + * 매개변수를 여러개 쓸 때는 ,로 구분합니다. + * 매개변수가 없음을 의미할때는 매개변수이름은 없이 void라고만 씁니다. + * + * 의미 + * 해당 이름이 특정 반환타입의 함수를 뜻한다고 정하고, 매개변수의 개수와 각각의 타입도 정합니다. + */ + +/* To Do: 반환 타입이 int이고 이름이 value이고, 매개변수가 int 타입 하나인 함수를 선언해보세요 */ +int value(int number); +int main() { + return value(5); +} + +/* + * 함수 이름: value + * 반환 타입: int + * 매개 변수: int x + * + * value 함수는 int 타입 매개 변수의 값을 그대로 반환한다. + */ +int value(int x) { + return x; +}