Language/C

C/C++ 포인터의 사용법

퓨림노 2011. 5. 21. 02:29
포인터를 쓰다가 잘안쓰는 방법인데...
이렇게 해두 포인터에 접근이 가능하다. 라고 메모해둔다.
머랄까...포인터두 사람마다 익숙한 문법이 있는데 저렇게 해두 된다는게...ㄷㄷㄷ
참 결과는 포인터를 순차적으로 저장하기 위한 것과 같다.  라고 말하고 싶다. 
(포인터에 접근하는 방법...아라고 말하고 싶네요)

#include 
using namespace std;

struct coorlist
{
	int x,y;
	struct coorlist * next;
};

void main()
{
	struct coorlist * list;
	struct coorlist ** range_l_s; /* array of pointers to start of bin list */
	

	list = (struct coorlist *) calloc( (size_t) (10), sizeof(struct coorlist) );
	range_l_s = (struct coorlist **) calloc( (size_t) 10, sizeof(struct coorlist *) );	

	int i;

	// init
	for(i=0; i<10; i++ )
	{
		list[i].x = i;
		list[i].y = i;		
	}

	int x, y;
	int list_count=0;

	for(i=0; i<10; i++ )
	{
		range_l_s[i] = list+list_count++;
	}

	int b=0;
}