help decode

Can someone try to explain this step to step?
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
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<iomanip>
using namespace std;
void func(int size);
int main()
{
	func(10);

	system("pause");
	return 0;
}


void func(int size)
{
	int *ptr1, *ptr2, *ptr3, count=0;
	ptr1 = new int[size];
	ptr2 = ptr1;
	*ptr2 = 1;
	while (count+1 < size)
	{
		ptr3 = ptr2++;
		*ptr2 = *ptr1 + *ptr3;
		if (count++ > 0)
		{
			ptr1 = &ptr1[1];
		}
	}
	for (int i=0; i<size; i++)
	{
		cout << *(ptr1-(size-2)+i) << " ";
	}
	cout << endl;
}

Thanks!
01 02 03 05 08 13 21 34 55 89

01 01 01 02 03 05 08 13 21 34


Basically pushes the row numbers 3 to the right.

If you have time, you can do a deep analysis of the code, like after every time a variable is changed, you can dump what that value currently is.

like: for(int i=0;i<size;++i) std::cout<<"ptr1("<<i<<") is:"<<ptr1[i]<<".\n";
(Just an example, if you did this after ptr1 it is initialized, they are all 0)
Topic archived. No new replies allowed.