Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int **a;
- a = (int**)malloc(10 * sizeof(int *));
- for (int i = 0; i < 10; i++)
- *(a+i) = (int *)malloc(10 * sizeof(int));
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- **a = 1;
- (*a)++;
- }
- a++;
- }
- int rows = 10, cols = 10
- int **a;
- // don't cast the return value of malloc
- a = malloc(rows * sizeof(*a));
- for (int i = 0; i < rows; i++)
- a[i] = malloc(cols * sizeof(**a));
- ...
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < cols; j++) {
- a[i][j] = 1;
- }
- }
Add Comment
Please, Sign In to add comment