회원 로그인
정보기억 정보기억에 체크할 경우 다음접속시 아이디와 패스워드를 입력하지 않으셔도 됩니다.
그러나, 개인PC가 아닐 경우 타인이 로그인할 수 있습니다.
PC를 여러사람이 사용하는 공공장소에서는 체크하지 마세요.
소셜네트워크 서비스를 통해서 로그인하시면 별도의 로그인 절차없이 회원서비스를 이용하실 수 있습니다.


최근 게시물

1.노션에서 작성 중

1.노션에서 작성 중

개편하기 전까지 노션에서 작성 중

2024.04.04//read more

2.ChatGPT

2.ChatGPT

OpenAI로 대규모 언어 모델대화형...

2023.03.16//read more

3.노코딩 게임 엔진 - 빌..

3.노코딩 게임 엔진 - 빌..

빌드 지원안드로이드iOS윈도우즈특이사...

2023.03.14//read more

4.(완료) 미접속 회원 정..

4.(완료) 미접속 회원 정..

[완료] 36명의 회원을 정리하였습니...

2023.02.16//read more

5.매뉴얼 플러스 - 전자제..



안정적인 DNS 서비스 DNSEver
DNS Powered by DNSEver.com


2차원 포인터

푸딩뱃살 | 2015.11.06 00:26 | 조회 2051
2차원 포인터


#include <iostream>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <Windows.h>

using namespace std;

void main(){

    int value = 10;
    int* pValue = &value;  // int 포인터 타입

    int** ppValue = &pValue; // (int*)* int* 포인터의 주소를 저장할 수 있는 주소

    int*** pppValue = &ppValue; // int*** pppValue : (int**)*

    // ppValue -> *pppValue;
    // pValue -> **pppValue;
    // Value -> ***pppValue;

    // 2차원 포인터 변수에는 1차원 포인터 변수의 주소만 저장할 수 있음
    // int** ppValue2 = &value; // 오류

    cout << "주소값들---" << endl;
    cout << "&value : " << &value << endl;
    cout << "pValue : " << pValue << endl;
    cout << "ppValue : " << ppValue << endl;
    cout << "&pValue : " << &pValue << endl;

    cout << endl;

    cout << "데이터값들---" << endl;
    cout << "value : " << value << endl;
    cout << "*(&value) : " << *(&value) << endl; // *(&value) 주소의 실체는 곧 value
    cout << "*pvalue : " << *pValue << endl;  // *pValue == &value
    cout << "*ppvalue : " << *ppValue << endl;  // *ppValue == &pValue
    cout << "**ppvalue : " << **ppValue << endl;  // **ppValue == *pValue == &value
}

2차원 배열 / 포인터
#include <iostream>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <Windows.h>

using namespace std;

void main() {
    //
    int iArray[3][4] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } };

    cout << "[int 배열 출력] ------" << endl;

    iArray[2][2] = 70;

    // 배열의 값과 주소를 출력
    cout << "iArray : " << iArray << endl;       // iArray의 시작 주소와 (2차배열 전체)
    cout << "iArray[0] : " << iArray[0] << endl; // iArray[0]의 주소는 같다
    cout << "iArray[1] : " << iArray[1] << endl;
    cout << "iArray[2] : " << iArray[2] << endl;
    cout << "iArray[3] : " << iArray[3] << endl;
    cout << endl;

    /* 차이
      (iArray + 1 + 1)
      (*(iArray + 1) + 1)
    */

    // &iArray[2]
    cout << "((iArray + 1 + 1) : " << ((iArray + 1) + 1) << endl;
    // &iArray[1][1], iArray[1] + 1, (*(iArray + 1) + 1) 모두 같다
    cout << "(*(iArray + 1) + 1) : " << (*(iArray + 1) + 1) << endl;
    // *(&iArray[1][1]), iArray[1][1], *(*(iArray + 1) + 1)  모두 같다
    cout << "*(*(iArray + 1) + 1) : " << *(*(iArray + 1) + 1) << endl;

    cout << endl;

    cout << endl;
    cout << "(iArray[0] + 0) : " << (iArray[0] + 0) << endl;
    cout << "(iArray[0] + 1) : " << (iArray[0] + 1) << endl;
    cout << "*(iArray[1] + 1) : " << *(iArray[1] + 2) << endl;
    cout << "*(*(iArray[1] + 1) + 2) : " << *(*(iArray + 1) + 2) << endl;
    cout << endl;
    // 오류:문법 오류
    // cout << "*(*(iArray[1] + 1) + 2) : " << *(*(iArray[1] + 1) + 2) << endl;
    // error C2088: '<<' : illegal for class
    // error C2100: illegal indirection
    // IntelliSense: operand of '*' must be a pointer
    cout << "iArray[1][2] : " << iArray[1][2] << endl;
}

2차원 배열 포인터
#include <iostream>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <Windows.h>

using namespace std;

const int WAVE_SIZE = 3;
const int MONSTER_COUNT = 4;

// 몬스터 젠 함수
void MonsterGen7(int type){
    // type 1,2 인간형
    // type 3,4 언데드형

    switch (type){
    case 1:
    case 2:
        cout << "인간형 몬스터 타이이 생성됩니다." << endl;
        break;
    case 3:
    case 4:
        cout << "언데드형 몬스터 타입이 생성됩니다." << endl;
        break;
    }

    switch (type) {
    case 1:
        cout << "멀록 몬스터가 생성되었습니다." << endl;
        break;
    case 2:
        cout << "오우거 몬스터가 생성되었습니다." << endl;
        break;
    case 3:
        cout << "언데드 기사 몬스터가 생성되었습니다." << endl;
        break;
    default:
        cout << "보스 몬스터가 생성되었습니다." << endl;
        break;
    }
}

// 2차원 배열 포인터를 이용해서 main()함수의 monsterGenType배열을 참조
void WaveStart7(int(*pMonsterGenType)[4]) {  //*pMonsterGenType)[4]의 [4]는 열의 갯수(정적 배열)
//void WaveStart(int refMonsterGenType[][4]) {  // 레퍼런스(참조)형
//void WaveStart(int monsterGenType[WAVE_SIZE][MONSTER_COUNT]) { // 배열형
    cout << "&pMonsterGenType[1][2] : " << &pMonsterGenType[1][2] << endl;
    cout << endl;
    for (int i = 0; i < WAVE_SIZE; i++){
        cout << i + 1 << "번째 웨이브가 시작되었습니다" << endl;
        // 1차원 반복문은 행배열의 반복 담당
        for (int j = 0; j < MONSTER_COUNT; j++){
            Sleep(2000);
            //cout << monsterGenType[i][j] << "타입의 몬스터가 생성되었습니다." << endl;  // 배열형
            MonsterGen7(*(*(pMonsterGenType + i) + j));  // == MonsterGen7(pMonsterGenType[i][j])
            //MonsterGen(refMonsterGenType[i][j]);  // 레퍼런스(참조)형
            //MonsterGen(*(*(refMonsterGenType + i) + j));  // 레퍼런스(참조)형
        }

        for (int k = 0; k < 4; k++){
            Sleep(500); cout << "경고! ";
        }
        cout << endl;
    }
}

void main() {

    // 자료형 배열명[행갯수][열갯수]
    int monsterGenType[WAVE_SIZE][MONSTER_COUNT] = {
        {1,1,2,2},  // 1웨이브 몬스터 생성 타입
        {2,2,3,3},  // 2웨이브 몬스터 생성 타입
        {3,3,3,4}  // 3웨이브 몬스터 생성 타입
    };

    cout << "&monsterGenType[1][2] => " << &monsterGenType[1][2] << endl;

    WaveStart7(monsterGenType);
}
285개(7/15페이지)
프로그래밍
번호 제목 글쓴이 조회 날짜
165 [C#] 네임스페이스 (namespace) 푸딩뱃살 3404 2015.11.14 17:34
164 [C#] 인터페이스 (Interface) 첨부파일 푸딩뱃살 2195 2015.11.13 18:17
163 [C/C++] Static(정적) 멤버 변수, 메소드 푸딩뱃살 2473 2015.11.13 10:32
162 [C/C++] 추상 클래스 - 오버라이드 / 업/다운캐스팅(형변환) / virtual(가상함수) 푸딩뱃살 4725 2015.11.12 02:00
161 [C/C++] 메소드 오버라이드 푸딩뱃살 1992 2015.11.12 01:51
160 [C#] 상속 (with Unity) 푸딩뱃살 5453 2015.11.10 16:25
159 [C/C++] 클래스 상속 푸딩뱃살 2245 2015.11.10 14:08
158 [C/C++] 객체 활용 푸딩뱃살 2470 2015.11.09 21:28
157 [C#] C# 객체 클래스 푸딩뱃살 3568 2015.11.08 15:51
156 [C/C++] 생성자 / 소멸자 / 오버로드 푸딩뱃살 2202 2015.11.07 01:23
155 [C/C++] 클래스 선언/정의, 객체 생성 푸딩뱃살 3567 2015.11.06 14:05
154 [C/C++] 로또 프로그램 푸딩뱃살 2284 2015.11.06 12:00
153 [C/C++] 2차원 동적 객체 배열 활용 푸딩뱃살 3649 2015.11.06 00:47
152 [C/C++] 2차원 배열 푸딩뱃살 2403 2015.11.06 00:30
>> [C/C++] 2차원 포인터 푸딩뱃살 2052 2015.11.06 00:26
150 [C/C++] 동적할당 푸딩뱃살 1805 2015.11.05 11:23
149 [C/C++] 당신의 프로그래밍에 디버깅 더하기 : Visual C++ 디버깅 기초에서 고급까지 첨부파일 푸딩뱃살 1451 2015.11.05 11:20
148 [C/C++] 포인터와 배열의 이해 푸딩뱃살 2013 2015.11.04 23:54
147 [C/C++] 포인터 푸딩뱃살 2191 2015.11.04 15:14
146 [C/C++] 일반 함수와 메소드간의 차이 푸딩뱃살 2430 2015.11.03 23:38