From 8d952e19e75d6a3c1abddca55b24739e9a8bf1be Mon Sep 17 00:00:00 2001 From: flykhan Date: Fri, 2 Jun 2023 03:58:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BD=E6=95=B0=E7=9A=84=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=A3=B0=E6=98=8E=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3_lesson/02_fun_declare/.gitignore | 73 ++++++++++++++++++++++ 3_lesson/02_fun_declare/02_fun_declare.pro | 6 ++ 3_lesson/02_fun_declare/main.c | 41 ++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 3_lesson/02_fun_declare/.gitignore create mode 100644 3_lesson/02_fun_declare/02_fun_declare.pro create mode 100644 3_lesson/02_fun_declare/main.c diff --git a/3_lesson/02_fun_declare/.gitignore b/3_lesson/02_fun_declare/.gitignore new file mode 100644 index 0000000..fab7372 --- /dev/null +++ b/3_lesson/02_fun_declare/.gitignore @@ -0,0 +1,73 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/3_lesson/02_fun_declare/02_fun_declare.pro b/3_lesson/02_fun_declare/02_fun_declare.pro new file mode 100644 index 0000000..fc18d89 --- /dev/null +++ b/3_lesson/02_fun_declare/02_fun_declare.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +CONFIG += console +CONFIG -= app_bundle +CONFIG -= qt + +SOURCES += main.c diff --git a/3_lesson/02_fun_declare/main.c b/3_lesson/02_fun_declare/main.c new file mode 100644 index 0000000..64dc6a5 --- /dev/null +++ b/3_lesson/02_fun_declare/main.c @@ -0,0 +1,41 @@ +#include + +// 函数的声明,一般当子函数在主函数的下方时,需要在主函数的上方进行声明 +void myfun1(); +void myfun2(int a, int b); +int myfun3(int a, int b); + +int main(int argc, char *argv[]) +{ + myfun1(); + + return 0; +} + +// 定义一个没有参数也没有返回值的函数 +void myfun1() +{ + printf("hello world\n"); + printf("nihao beijing\n"); + printf("welcome to 1000phone\n"); + + return; +} + +// 定义一个有参数的函数 +void myfun2(int a, int b) +{ + int sum; + sum = a + b; + + printf("%d + %d = %d\n", a, b, sum); +} + +// 定义一个有返回值的函数 +int myfun3(int a, int b) +{ + int sum; + sum = a + b; + + return sum; +}