Search results for '배열'

포인트 배열

2008/11/18 14:39

포인트 배열 Passion 배열, 포인터


*(ptr+0) 주소

*(*(ptr+0)) 값
생각보다 개념 이해 하기가 힘들다.. ㅠㅠ
저작자 표시 비영리 동일 조건 변경 허락

배열 값

2008/08/19 12:39

배열 값 Passion C언어, 배열


#include<stdio.h>
void main()
{
 int i;
 int array[]={10,20,30,40,50};
 int *ptr;

 ptr =array;

 printf("ptr의 자기주소 :%d\n" , &ptr);
 printf("ptr의 값       :%d\n" , ptr);
 printf("array시작 주소 :%d\n" , array);

 printf("\n");

 for(i=0;i<5;i++) printf("array[%d]의 주소 : %d ==> %d\n" , i ,&array[i] , array[i]);

 printf("\n");

 printf("*(ptr+2) : %d\n", *(ptr+2));
 printf("*(ptr+2)+6 : %d\n", *(ptr+2)+6);

 printf("     ptr+2 : %d\n", ptr+2);
 printf(" (ptr+2)-1 : %d\n" , (ptr+2)-1);
 printf("*(ptr+2)-1 : %d\n" , *(ptr+2)-1);

}

포인터에 메모리를 할당하여 복사

2008/08/12 12:42

포인터에 메모리를 할당하여 복사 Passion C언어, 배열


#include<stdio.h>

void main()
{
 int s,k,i;
 int a[]={0,1,2,3,4,5,6,7,8,9,10};
 int *p;

 printf("복사 시작 요소..?");
 scanf("%d" , &s);

 printf("끝 요소 ..?");
 scanf("%d", &k);

//p에 메로리를 할당
 p=(int*)malloc(sizeof(int)*(k-s+1));
//a[s] ~ a[k]을 p에 복사
 memcpy(p, &a[s], sizeof(int)*(k-s+1));
//복사된 p[]를 표시
 for(i=0;i<k-s+1;i++)
  printf("p[%d] : %d\n" ,i,p[i]);
//p에 할당된 메모리를 자유롭게 해제
 free(p);
}