Created
July 15, 2012 12:54
-
-
Save hadashiA/3116697 to your computer and use it in GitHub Desktop.
動的に確保した多次元配列のなかの、特定の要素のポインタを得る
This file contains hidden or 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> | |
#define X (50) | |
#define Y (50) | |
int main(int argc, char **argv) { | |
int **matrix = (int **)malloc(sizeof(int *) * X); | |
int x, y; | |
for (x = 0; x < X; x++) { | |
matrix[x] = (int *)malloc(sizeof(int) * Y); | |
} | |
for (x = 0; x < X; x++) { | |
for (y = 0; y < Y; y++) { | |
matrix[x][y] = x + y; | |
} | |
} | |
printf("%d = %d\n", matrix[5][10], *(*(matrix + 5)) + 10); | |
printf("%p = %p\n", &matrix[5][10], (*(matrix + 5)) + 10); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment