조회 수 4260 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

배열과 포인터, 등가포인터 예제

#include <stdio.h>

int a[2][3] = {{1,2,3},{4,5,6}};
int b[2][3] = {{10,20,30},{40,50,60}};
int (*c[2])[3] = {b, a};
int (**p)[3] = c;

// c[1] => a
// 6: a[1][2] = c[1][1][2] = f1()[1][2]
// f1() = c[1]

// int (*[2])[3] => c
// int (*)[3] => c[1]

int (*f1(void))[3]
{
     return c[1];
}

// int (*[2])[3] => c
// int (**)[3] => c 등가

// f2() = c+1
// f2()-1 = c
// 6 = a[1][2] = c[1][1][2] = (f2()-1)[1][1][2] = f2()[0][1][2]

int (**f2(void))[3]
{
     return c+1;
}

// int a[2][3] => a
// int [3] => a[0]
// int *


// f3()+1 = a[0]
// 6 = a[1][2] = a[0][5] = (f3()+1)[5] = f3()[6]


int * f3(void)
{
     return a[0]-1;
}

//int (**)[3] => p
// p = c => c[1] = a = p[1]
// p[1] = a, a[1][2] = p[1][1][2]

int (**f4(void))[3]
{
    return p;
}


// int (*(*)[2])[3] => &c
// *f5() = c
// c[1] = a, a[1][2] = c[1][1][2] = (*f5())[1][1][2] = f5()[0][1][1][2]


int (*(*f5(void))[2])[3]
{
    return &c;
}

int main(void)
{
     printf("6=%d\n", f1()[1][2]);
     printf("6=%d\n", f2()[0][1][2]);
     printf("6=%d\n", f3()[6]);
     printf("6=%d\n", f4()[1][1][2]);
     printf("6=%d\n", f5()[0][1][1][2]);

     return 0;
}

 


  1. No Image notice

    C Programming FAQs(한글번역 pdf문서)

    Date2014.03.18 Bymakersweb Views34795
    read more
  2. No Image

    비트 필드의 크기는 해당 유형의 크기를 초과할 수 없다.

    Date2023.04.25 CategoryC Bymakersweb Views4010
    Read More
  3. flexible array member 에 대해서

    Date2020.02.20 CategoryC Bymakersweb Views6105
    Read More
  4. C++로 플러그인 개발

    Date2019.12.08 CategoryC++ Bymakersweb Views5099
    Read More
  5. No Image

    배열과 포인터, 등가포인터 예제

    Date2019.01.16 CategoryC Bymakersweb Views4260
    Read More
  6. 싱글톤 객체생성 패턴에 대해서

    Date2018.07.01 CategoryC++ Bymakersweb Views7226
    Read More
  7. No Image

    함수포인터와 typedef로의 선언

    Date2018.02.03 CategoryC Bymakersweb Views4314
    Read More
  8. No Image

    예제소스를 통해 리틀엔디안(Little endian)과 빅엔디안(Big endian)의 차이점 알아보기

    Date2014.05.24 CategoryC Bypjk Views11072
    Read More
  9. switch와 if 중 어느 것이 더 빠른가

    Date2017.01.31 CategoryC Bymakersweb Views6368
    Read More
  10. No Image

    구조체 배열을 반환하는 함수를 반환하는 함수를 호출하여 구조체 멤버 배열 요소 접근하기

    Date2016.05.22 Bymakersweb Views13539
    Read More
  11. No Image

    c/c++문자열, 유니코드 관련 함수

    Date2015.07.09 Bymakersweb Views8685
    Read More
  12. No Image

    volatile이 정확히 어떤 의미를 가지는 건가요?

    Date2014.09.30 CategoryC Bypjk Views8396
    Read More
  13. No Image

    HEX(16진수) to ASCII(아스키) 변환 코드

    Date2014.08.24 Bypjk Views38407
    Read More
  14. No Image

    strcmp, wcscmp, _tcscmp

    Date2014.07.18 Bypjk Views13690
    Read More
  15. No Image

    클래스 멤버에 대한 액세스 제어

    Date2014.06.27 CategoryC++ Bypjk Views7903
    Read More
  16. unsigned형의 모든 상수에는 접미사 ‘U’를 사용하여야 한다.

    Date2014.05.24 CategoryC Bypjk Views41930
    Read More
  17. No Image

    void형 포인터

    Date2014.05.24 CategoryC Bypjk Views8481
    Read More
  18. No Image

    함수 포인터의 배열

    Date2014.05.24 Bypjk Views10882
    Read More
  19. 구조체 메모리 저장방식 #pragma pack

    Date2014.05.24 CategoryC++ Bypjk Views8213
    Read More
  20. No Image

    Bit fields(비트필드)

    Date2014.05.24 Bypjk Views6815
    Read More
  21. No Image

    영어를 C언어로, 또는 C언어를 영어로 변환 해주는 cdecl

    Date2014.03.19 Bymakersweb Views12146
    Read More
Board Pagination Prev 1 2 Next
/ 2