: Please help me. I need to translate the ff C++ code snippet into C (the code here is simplified, e.g. hard coded numbers, but it reflects the code I want to translate without precision loss):
:
:
int **int2dimarray = new int*[3];
: for( int i=0; i<3; i++ )
: int2dimarray[i] = new int[5];
:
: for( int i=0; i<3 ; i++ )
: delete []int2dimarray[i];
: delete []int2dimarray;
:
: I understand I could write it as
int2dimarray[3][5] but I need to de/allocate memory dynamically. Am I doing the right thing if I do the ff?
:
:
int **int2dimarray;
: int i;
:
: int2dimarray = malloc( sizeof(int)*3 );
: for( i=0; i<3; i++ )
: int2dimarray[i] = (int *) malloc ( sizeof(int)*5 );
:
: for( i=0; i!=3; i++ )
: free( int2dimarray[i] );
: free( int2dimarray );
:
: Thanks for reading. Hope someone can help me asap.
:
: #7
:
Code looks correct...