Add 02-pass-by-ref resources
This commit is contained in:
parent
f5e8d84eec
commit
66c2209979
20
02-pass-by-ref/no-ref.cpp
Normal file
20
02-pass-by-ref/no-ref.cpp
Normal 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
20
02-pass-by-ref/ref.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user