how refrence and pointer works in a function

Solutions on MaxInterview for how refrence and pointer works in a function by the best coders in the world

showing results for - "how refrence and pointer works in a function"
Pietro
13 Mar 2018
1
2int func (int a) {
3	a = 300;
4	return a;
5}
6
7int func2 (int& a) {
8	a = -2;
9	return a;
10}
11
12int func3 (long* a) {
13	*a = 10;
14	return *a;
15}
16
17
18int main()
19{
20	
21	int a = 0;
22	int b = 0;
23	int c = 0;
24
25	long *d = new long (300);
26
27	cout << func(a) << ' ' << a << '\n'; // 300  0
28
29	cout << func2(b) << ' ' << b << '\n'; // -2  -2
30
31	cout << func3(d) << ' ' << *d << '\n'; // 10  10
32
33	keep_window_open();
34}