-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
53 lines (44 loc) · 889 Bytes
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
void foo()
{
int i[] = {1,2,3,4};
int *p = &i[2];
cout<<p[-1] <<"\n";
}
// https://www.programiz.com/cpp-programming/library-function/cstring/strncpy
void f(std::string const& s)
{
char buffer[256];
strncpy(buffer, s.c_str(), 256);
}
int foo(int x){
if(x<=0)
return 0;
else
return foo(x-2)+x;
}
class A
{
public:
A() {cout<<"Constructed! ";}
A(A const& o) {cout<<"Copy!";}
};
void Fa(A a){}
void Fb(A & a){}
int main(){
foo();
f("hasdfasdfasdfasdfasdfasdfasdfasdfelo");
int * p = new int;
int j = *p;
int *r = p;
(*p) = 5;
int k = (*p);
cout<<k<<"\n";
cout<<foo(8);
A a;
Fa(a); //when calling this function, i also am declaring a new object
// Fb(a); //but here, instead, I am just passing by reference.
A b(a);
return 0;
}