Created
April 22, 2013 14:22
-
-
Save hanjae-jea/5435468 to your computer and use it in GitHub Desktop.
[NHN NEXT] 배열참조하기, malloc함수로 받은 메모리에서 이차원으로 참조받는 방법 소개. 배열과 포인터 부분에서 사용되었습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(void) | |
{ | |
int Arr[3][5]; | |
int *Brr = (int*)malloc( sizeof(int) * 15 ); | |
int **Crr = (int**)malloc( sizeof(int*) * 3); | |
int rowIdx = 1, colIdx = 3, colSize = 5; | |
Crr[0] = Brr + 0 * colSize; | |
Crr[1] = Brr + 1 * colSize; | |
Crr[2] = Brr + 2 * colSize; | |
Arr[rowIdx][colIdx] = 28; | |
Brr[rowIdx * colSize + colIdx] = 28; | |
printf("%d == 28??!\n", Crr[rowIdx][colIdx]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment