Created
December 21, 2013 15:31
-
-
Save teddypickerfromul/8070852 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
~ ➤ indent -st -bap -bli0 -i4 -l79 -ncs -npcs -npsl -fca -lc79 -fc1 -ts4 malloc_test.c | |
#include <stdlib.h> | |
#include <stdio.h> | |
#define N 5 | |
void processMatrix(int **matrix); | |
void printMatrix(int **matrix) | |
{ | |
printf("\nfunc scope adress %p\n", matrix); | |
for (int i = 0; i < N; i++) | |
{ | |
printf("\n"); | |
for (int j = 0; j < N; j++) | |
{ | |
printf("%d ", matrix[i][i]); | |
} | |
} | |
} | |
int main(int argc, char *argv[]) | |
{ | |
int i; | |
int **matrix; | |
matrix = (int **)malloc(N * sizeof(int *)); | |
for (i = 0; i < N; i++) | |
{ | |
matrix[i] = (int *)malloc(N * sizeof(int)); | |
} | |
printf("global scope adress %p\n", matrix); | |
printMatrix(matrix); | |
for (int i = 0; i < N; i++) | |
{ | |
for (int j = 0; j < N; j++) | |
{ | |
matrix[i][j] += 1; | |
} | |
} | |
printMatrix(matrix); | |
for (i = 0; i < N; i++) | |
{ | |
free(matrix[i++]); | |
} | |
free(matrix); | |
return 0; | |
} | |
~ ➤ gcc malloc_test.c -o malloc_test -g -Wextra -std=c99 | |
~ ➤ ./malloc_test | |
global scope adress 0x854f008 | |
func scope adress 0x854f008 | |
0 0 0 0 0 | |
0 0 0 0 0 | |
0 0 0 0 0 | |
0 0 0 0 0 | |
0 0 0 0 0 | |
func scope adress 0x854f008 | |
1 1 1 1 1 | |
1 1 1 1 1 | |
1 1 1 1 1 | |
1 1 1 1 1 | |
1 1 1 1 1 % | |
~ ➤ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment