help with pointers

can someone explain how we got the output please

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
  #include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

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;

}

void main ()
{

	func(10);
	system ("pause");
}
too much thinking to do :/

http://www.cplusplus.com/doc/tutorial/pointers/ has all the info you need

also you should use a debugger on this programm and just run through, step by step
Why did you make your main a void? You need to make it an int first and have it return 0 (to be "grammatically" correct).

I don't understand what your problem is. Your program is returning a Fibonnaci sequence so it appears to be functioning as normal (assuming that's what you wanted it to do). What are you confused about?
Topic archived. No new replies allowed.