Add 02-pass-by-ref resources

This commit is contained in:
Nicolás A. Ortega Froysa 2022-06-17 14:48:09 +02:00
parent f5e8d84eec
commit 66c2209979
2 changed files with 40 additions and 0 deletions

20
02-pass-by-ref/no-ref.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <cstdlib>
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;
}

20
02-pass-by-ref/ref.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <cstdlib>
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;
}