본문 바로가기
코스웨어/14년 스마트컨트롤러

20140414 업무일지 김재성 출석번호 7

by 알 수 없는 사용자 2014. 4. 14.
728x90
반응형

 















연결 리스트

 #include <stdio.h>


struct smart
{
  int iNum;
  struct smart * self;
};

int main()
{
  struct smart A = {10};  
  struct smart B = {20};
  struct smart C = {30};
  struct smart D = {40};
  struct smart * p;
  
  A.self = &B;                     
  B.self = &C;
  C.self = &D;
  
  = &A;   최초 p는 A의 주소를 가리킴요

  while(0 != p)
  {
    printf("%d->", p->iNum); 
    = p->self; p->self값은 다음주소를 가르키져?
  
  }
  printf("NULL \n");
  return 0;
}




 #include <stdio.h>


struct bigdata
{
  int iNum;
  char data[1000];
  struct bigdata * next;    
};

int main()
{
  struct bigdata test[4];
  struct bigdata temp;
  struct bigdata * p;
  int iCnt;

  test[0].iNum = 0;
  test[1].iNum = 1;
  test[2].iNum = 2;
  test[3].iNum = 3;

  test[0].next = &test[1]; 연결리스트
  test[1].next = &test[2];
  test[2].next = &test[3];
  test[3].next = 0;



  for(iCnt=04>iCnt; iCnt++)
  {
    printf("%d->", test[iCnt].iNum);
  }

//  temp.iNum = test[0].iNum; 구조체가 10메가면 어쩔래? 아래의 노란펜 포인터로 쓰면 간단(ㅜ.ㅜ)하다.
//        test[0].iNum = test[1].iNum;
//        test[1].iNum = temp.iNum;

  printf("\n");
  for(iCnt=04>iCnt; iCnt++)
  {
    printf("%d->", test[iCnt].iNum);
  }

  printf("\n");
  
  for(p=test; p!=0; p=p->next)위에서 한것과 똑같다.
  {
    printf("%d->", p->iNum);
  }
  
  printf("\n");

    
  = &test[1];      
  test[0].next = &test[2];
  p->next = test[2].next;
  test[2].next = p;

  for(p=test; p!=0; p=p->next)
  {
    
    printf("%d->", p->iNum);
  }

  return 0;  

}

위의 노란펜부분의 메모리 구조 예시





변수선언으러 보는 메모리 다섯가지 구조

 #include <stdio.h>


  int A;
  int B;
  int C;        //비에스에스영역
  int D = 100;  
  int E = 200;  
  int F = 300;  //데이타영역

int main()
{
  int G;        //스택영역
  int H;  
  int I;  
  
  int * p;
  p = malloc(4);   //힙영역
      //말록은 주소값을 반환
  free(p);
  
  printf("Code (%08X)\n"&main); //코드영역
  printf("Bss  (%08X)\n"&A); 
  printf("Data (%08X)\n"&D); 
  printf("Stack(%08X)\n"&G); 
  printf("Heap (%08X)\n", p);  

  return 0;
}

포인터 기본기 많이 쌓아야할듯 ㅈㅅ

 

 

 

 

즐감요! ㅋㅋㅋㅋㅋㅋㅋ

 

728x90