dynamic memory allocation (2)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <stdio.h> #include <stdlib.h> int main(void) { int row = 3, column = 4; int* _Array = (int*) calloc (row * column, sizeof (int)); int count = 0; int horizon = 0, vertical = 0; for (vertical = 0; vertical < column; vertical++) { for (horizon = 0; horizon < row; horizon++) { *(_Array + (vertical * row) + horizon) = ++count; } } // print for (vertical = 0; vertical < column; vertical++) { for (horizon = 0; horizon < row; horizon++) { printf ("%3d", *(_Array + (vertical * row) + horizon)); } printf ("\n"); } free (_Array); return 0; } | cs |
0 개의 댓글:
댓글 쓰기