From 66c220997985c0e294911cea09753b6fa2fab52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Fri, 17 Jun 2022 14:48:09 +0200 Subject: [PATCH] Add 02-pass-by-ref resources --- 02-pass-by-ref/no-ref.cpp | 20 ++++++++++++++++++++ 02-pass-by-ref/ref.cpp | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 02-pass-by-ref/no-ref.cpp create mode 100644 02-pass-by-ref/ref.cpp diff --git a/02-pass-by-ref/no-ref.cpp b/02-pass-by-ref/no-ref.cpp new file mode 100644 index 0000000..00048ef --- /dev/null +++ b/02-pass-by-ref/no-ref.cpp @@ -0,0 +1,20 @@ +#include + +struct A +{ + char str[16]; +}; + +int len(struct A a) +{ + int count; + for(count = 0; a.str[count] not_eq '\0'; ++count); + return count; +} + +int main() +{ + struct A a = { .str = "Hello, World!" }; + int res = len(a); + return EXIT_SUCCESS; +} diff --git a/02-pass-by-ref/ref.cpp b/02-pass-by-ref/ref.cpp new file mode 100644 index 0000000..8d77cec --- /dev/null +++ b/02-pass-by-ref/ref.cpp @@ -0,0 +1,20 @@ +#include + +struct A +{ + char str[16]; +}; + +int len(struct A &a) +{ + int count; + for(count = 0; a.str[count] not_eq '\0'; ++count); + return count; +} + +int main() +{ + struct A a = { .str = "Hello, World!" }; + int res = len(a); + return EXIT_SUCCESS; +}