Initialize two 2D arrays and fill the first column and first row of one of the arrays with 0 along with Dynamic memory allocation










1















This function should initialize arrays C[m+1][n+1] and B[m][n] and fill the first row and first column of C with zeros. Note: int*** C refers to a pointer points to the 2D integer array. Please correct the error.



void initLCSTable(int*** C, char*** B, int m, int n)
{
C[m + 1][n + 1] = 0; //i don't know if this makes the 1st row & column to 0
for (int row = 0; row < m; row++)

for (int col = 0; col < n; col++)

C[m][n] = 0;

B[m][n];

void printLengthTable(int** C, int m, int n);
void printArrowTable(char** B, int m, int n);

//The following function releases the memory space table C & B
occupied
void freeLCSTable(int** C, char** B, int m)

// add code here. Please assist me in this function.



main
int** C;
char** B;
initLCSTable(&C, &B, m, n);

cout << "nTable C" << endl;
printLengthTable(C, m, n);

cout << "nTable B" << endl;
printArrowTable(B, m, n);
return 0;



//This function print the 2D length array C
//Note: array C has m+1 rows and n+1 column
void printLengthTable(int** C, int m, int n)

for (int i = 0; i <= m; i++)

for (int j = 0; j <= n; j++)

cout << C[i][j] << " ";

cout << endl;



//******************************************
//This function print the 2D arrow array B
//Note: array B has m rows and n column
void printArrowTable(char** B, int m, int n)

for (int i = 0; i < m; i++)

for (int j = 0; j < n; j++)

cout << B[i][j] << " ";

cout << endl;




Output should look like this (ignore the non-zeros since that is a different Longest Subsequence question all together):



enter image description here










share|improve this question
























  • I'm not comfortable answering this question because you have not made a credible attempt at solving it yourself yet, but here is a hint to get you started: How do I declare a 2d array in C++ using new?

    – user4581301
    Nov 14 '18 at 5:14











  • A side note: You don't want to do this in C++. The preferred approach would be nesting std::vectors or a matrix class wrapper around a single vector to make the vector appear to be 2 dimensional

    – user4581301
    Nov 14 '18 at 5:18











  • @user4581301 I have now made an attempt at trying to initializing the first row and column to 0s. But I'm not sure if Im wrong since I cannot check because I don't know how to release the memory in the freeLCStable function. (I'm really sorry but I'll highly appreciate it if you can assist me)

    – Ayaan
    Nov 14 '18 at 5:48











  • @user4581301 I was suggested to use std::vector as well by other users here but my professor wants me to do this way specifically.. (sorry again)

    – Ayaan
    Nov 14 '18 at 5:50











  • C[m + 1][n + 1] = 0; //i don't know if this makes the 1st row & column to 0 doesn't allocate anything. Read the link about how to declare a 2D array. You can't do jack until you allocate storage.

    – user4581301
    Nov 14 '18 at 6:31















1















This function should initialize arrays C[m+1][n+1] and B[m][n] and fill the first row and first column of C with zeros. Note: int*** C refers to a pointer points to the 2D integer array. Please correct the error.



void initLCSTable(int*** C, char*** B, int m, int n)
{
C[m + 1][n + 1] = 0; //i don't know if this makes the 1st row & column to 0
for (int row = 0; row < m; row++)

for (int col = 0; col < n; col++)

C[m][n] = 0;

B[m][n];

void printLengthTable(int** C, int m, int n);
void printArrowTable(char** B, int m, int n);

//The following function releases the memory space table C & B
occupied
void freeLCSTable(int** C, char** B, int m)

// add code here. Please assist me in this function.



main
int** C;
char** B;
initLCSTable(&C, &B, m, n);

cout << "nTable C" << endl;
printLengthTable(C, m, n);

cout << "nTable B" << endl;
printArrowTable(B, m, n);
return 0;



//This function print the 2D length array C
//Note: array C has m+1 rows and n+1 column
void printLengthTable(int** C, int m, int n)

for (int i = 0; i <= m; i++)

for (int j = 0; j <= n; j++)

cout << C[i][j] << " ";

cout << endl;



//******************************************
//This function print the 2D arrow array B
//Note: array B has m rows and n column
void printArrowTable(char** B, int m, int n)

for (int i = 0; i < m; i++)

for (int j = 0; j < n; j++)

cout << B[i][j] << " ";

cout << endl;




Output should look like this (ignore the non-zeros since that is a different Longest Subsequence question all together):



enter image description here










share|improve this question
























  • I'm not comfortable answering this question because you have not made a credible attempt at solving it yourself yet, but here is a hint to get you started: How do I declare a 2d array in C++ using new?

    – user4581301
    Nov 14 '18 at 5:14











  • A side note: You don't want to do this in C++. The preferred approach would be nesting std::vectors or a matrix class wrapper around a single vector to make the vector appear to be 2 dimensional

    – user4581301
    Nov 14 '18 at 5:18











  • @user4581301 I have now made an attempt at trying to initializing the first row and column to 0s. But I'm not sure if Im wrong since I cannot check because I don't know how to release the memory in the freeLCStable function. (I'm really sorry but I'll highly appreciate it if you can assist me)

    – Ayaan
    Nov 14 '18 at 5:48











  • @user4581301 I was suggested to use std::vector as well by other users here but my professor wants me to do this way specifically.. (sorry again)

    – Ayaan
    Nov 14 '18 at 5:50











  • C[m + 1][n + 1] = 0; //i don't know if this makes the 1st row & column to 0 doesn't allocate anything. Read the link about how to declare a 2D array. You can't do jack until you allocate storage.

    – user4581301
    Nov 14 '18 at 6:31













1












1








1








This function should initialize arrays C[m+1][n+1] and B[m][n] and fill the first row and first column of C with zeros. Note: int*** C refers to a pointer points to the 2D integer array. Please correct the error.



void initLCSTable(int*** C, char*** B, int m, int n)
{
C[m + 1][n + 1] = 0; //i don't know if this makes the 1st row & column to 0
for (int row = 0; row < m; row++)

for (int col = 0; col < n; col++)

C[m][n] = 0;

B[m][n];

void printLengthTable(int** C, int m, int n);
void printArrowTable(char** B, int m, int n);

//The following function releases the memory space table C & B
occupied
void freeLCSTable(int** C, char** B, int m)

// add code here. Please assist me in this function.



main
int** C;
char** B;
initLCSTable(&C, &B, m, n);

cout << "nTable C" << endl;
printLengthTable(C, m, n);

cout << "nTable B" << endl;
printArrowTable(B, m, n);
return 0;



//This function print the 2D length array C
//Note: array C has m+1 rows and n+1 column
void printLengthTable(int** C, int m, int n)

for (int i = 0; i <= m; i++)

for (int j = 0; j <= n; j++)

cout << C[i][j] << " ";

cout << endl;



//******************************************
//This function print the 2D arrow array B
//Note: array B has m rows and n column
void printArrowTable(char** B, int m, int n)

for (int i = 0; i < m; i++)

for (int j = 0; j < n; j++)

cout << B[i][j] << " ";

cout << endl;




Output should look like this (ignore the non-zeros since that is a different Longest Subsequence question all together):



enter image description here










share|improve this question
















This function should initialize arrays C[m+1][n+1] and B[m][n] and fill the first row and first column of C with zeros. Note: int*** C refers to a pointer points to the 2D integer array. Please correct the error.



void initLCSTable(int*** C, char*** B, int m, int n)
{
C[m + 1][n + 1] = 0; //i don't know if this makes the 1st row & column to 0
for (int row = 0; row < m; row++)

for (int col = 0; col < n; col++)

C[m][n] = 0;

B[m][n];

void printLengthTable(int** C, int m, int n);
void printArrowTable(char** B, int m, int n);

//The following function releases the memory space table C & B
occupied
void freeLCSTable(int** C, char** B, int m)

// add code here. Please assist me in this function.



main
int** C;
char** B;
initLCSTable(&C, &B, m, n);

cout << "nTable C" << endl;
printLengthTable(C, m, n);

cout << "nTable B" << endl;
printArrowTable(B, m, n);
return 0;



//This function print the 2D length array C
//Note: array C has m+1 rows and n+1 column
void printLengthTable(int** C, int m, int n)

for (int i = 0; i <= m; i++)

for (int j = 0; j <= n; j++)

cout << C[i][j] << " ";

cout << endl;



//******************************************
//This function print the 2D arrow array B
//Note: array B has m rows and n column
void printArrowTable(char** B, int m, int n)

for (int i = 0; i < m; i++)

for (int j = 0; j < n; j++)

cout << B[i][j] << " ";

cout << endl;




Output should look like this (ignore the non-zeros since that is a different Longest Subsequence question all together):



enter image description here







c++ arrays multidimensional-array dynamic-memory-allocation lcs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 5:46







Ayaan

















asked Nov 14 '18 at 4:17









AyaanAyaan

174




174












  • I'm not comfortable answering this question because you have not made a credible attempt at solving it yourself yet, but here is a hint to get you started: How do I declare a 2d array in C++ using new?

    – user4581301
    Nov 14 '18 at 5:14











  • A side note: You don't want to do this in C++. The preferred approach would be nesting std::vectors or a matrix class wrapper around a single vector to make the vector appear to be 2 dimensional

    – user4581301
    Nov 14 '18 at 5:18











  • @user4581301 I have now made an attempt at trying to initializing the first row and column to 0s. But I'm not sure if Im wrong since I cannot check because I don't know how to release the memory in the freeLCStable function. (I'm really sorry but I'll highly appreciate it if you can assist me)

    – Ayaan
    Nov 14 '18 at 5:48











  • @user4581301 I was suggested to use std::vector as well by other users here but my professor wants me to do this way specifically.. (sorry again)

    – Ayaan
    Nov 14 '18 at 5:50











  • C[m + 1][n + 1] = 0; //i don't know if this makes the 1st row & column to 0 doesn't allocate anything. Read the link about how to declare a 2D array. You can't do jack until you allocate storage.

    – user4581301
    Nov 14 '18 at 6:31

















  • I'm not comfortable answering this question because you have not made a credible attempt at solving it yourself yet, but here is a hint to get you started: How do I declare a 2d array in C++ using new?

    – user4581301
    Nov 14 '18 at 5:14











  • A side note: You don't want to do this in C++. The preferred approach would be nesting std::vectors or a matrix class wrapper around a single vector to make the vector appear to be 2 dimensional

    – user4581301
    Nov 14 '18 at 5:18











  • @user4581301 I have now made an attempt at trying to initializing the first row and column to 0s. But I'm not sure if Im wrong since I cannot check because I don't know how to release the memory in the freeLCStable function. (I'm really sorry but I'll highly appreciate it if you can assist me)

    – Ayaan
    Nov 14 '18 at 5:48











  • @user4581301 I was suggested to use std::vector as well by other users here but my professor wants me to do this way specifically.. (sorry again)

    – Ayaan
    Nov 14 '18 at 5:50











  • C[m + 1][n + 1] = 0; //i don't know if this makes the 1st row & column to 0 doesn't allocate anything. Read the link about how to declare a 2D array. You can't do jack until you allocate storage.

    – user4581301
    Nov 14 '18 at 6:31
















I'm not comfortable answering this question because you have not made a credible attempt at solving it yourself yet, but here is a hint to get you started: How do I declare a 2d array in C++ using new?

– user4581301
Nov 14 '18 at 5:14





I'm not comfortable answering this question because you have not made a credible attempt at solving it yourself yet, but here is a hint to get you started: How do I declare a 2d array in C++ using new?

– user4581301
Nov 14 '18 at 5:14













A side note: You don't want to do this in C++. The preferred approach would be nesting std::vectors or a matrix class wrapper around a single vector to make the vector appear to be 2 dimensional

– user4581301
Nov 14 '18 at 5:18





A side note: You don't want to do this in C++. The preferred approach would be nesting std::vectors or a matrix class wrapper around a single vector to make the vector appear to be 2 dimensional

– user4581301
Nov 14 '18 at 5:18













@user4581301 I have now made an attempt at trying to initializing the first row and column to 0s. But I'm not sure if Im wrong since I cannot check because I don't know how to release the memory in the freeLCStable function. (I'm really sorry but I'll highly appreciate it if you can assist me)

– Ayaan
Nov 14 '18 at 5:48





@user4581301 I have now made an attempt at trying to initializing the first row and column to 0s. But I'm not sure if Im wrong since I cannot check because I don't know how to release the memory in the freeLCStable function. (I'm really sorry but I'll highly appreciate it if you can assist me)

– Ayaan
Nov 14 '18 at 5:48













@user4581301 I was suggested to use std::vector as well by other users here but my professor wants me to do this way specifically.. (sorry again)

– Ayaan
Nov 14 '18 at 5:50





@user4581301 I was suggested to use std::vector as well by other users here but my professor wants me to do this way specifically.. (sorry again)

– Ayaan
Nov 14 '18 at 5:50













C[m + 1][n + 1] = 0; //i don't know if this makes the 1st row & column to 0 doesn't allocate anything. Read the link about how to declare a 2D array. You can't do jack until you allocate storage.

– user4581301
Nov 14 '18 at 6:31





C[m + 1][n + 1] = 0; //i don't know if this makes the 1st row & column to 0 doesn't allocate anything. Read the link about how to declare a 2D array. You can't do jack until you allocate storage.

– user4581301
Nov 14 '18 at 6:31












1 Answer
1






active

oldest

votes


















0














As long as you initialize part of the array, the rest will be default-initialized.



C[m + 1][n + 1] = 0; // Zero-initialized
C[m + 1][n + 1] = 0; // Same ^
C[m + 1][n + 1] = 1; // Zero-intialized except for [0][0] = 1
C[m + 1][n + 1] = 1; // Same ^
C[m + 1][n + 1]; // Uninitialized!


There are some contexts where arrays are zero-initialized anyway, but it doesn't hurt to do so explicitly.



Note that if you want to initialize with values other than zero, you'd be (mostly) out of luck. I've done work recently with template metaprogramming that would help...



// You can subclass this type, add it as a member, etc.
template<class T, T... I> struct Seq
typedef T value_type [sizeof...(I)];
// If you want to use it directly from here:
static constexpr value_type value = I...;
// Don't bother trying with any variation of...
// static constexpr value_type to_array(void) return I...;
;
template<class T, T... I0, T... I1>
auto operator+(Seq<T, I0...> const&, Seq<T, I1...> const&)
-> Seq<T, I0+I1...> return ;
template<class T, T... I0, T... I1>
auto operator<<(Seq<T, I0...> const&, Seq<T, I1...> const&)
-> Seq<T, I0..., I1...> return ;
// ... more Seq manipulation ...


I can use this to define ranges of numbers, binomial coefficients, etc. and as long as I still have some form of access to the template arguments, I can make an array of it. (That includes moving around a Seq<...> as an abstract T until the function where it's used.) I'd love to know what more can be done with this. I tried returning an initializer_list and defining an array out of that, but no luck (array initializers apparently only look like initializer_lists.)






share|improve this answer























  • okay but how do I complete the void freeLCSTable() function above?

    – Ayaan
    Nov 14 '18 at 4:51











  • Sorry, I'm not sure, and I'm not sure I answered the question looking at your code again. I work almost exclusively on the stack. It looks like you're assigning an array to a pointer that was already allocated, which would mean that the original is never freed and freeLCSTable would try to free the array that's on the stack. Hopefully someone with more dynamic memory experience could chime in.

    – John P
    Nov 14 '18 at 5:03










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293132%2finitialize-two-2d-arrays-and-fill-the-first-column-and-first-row-of-one-of-the-a%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














As long as you initialize part of the array, the rest will be default-initialized.



C[m + 1][n + 1] = 0; // Zero-initialized
C[m + 1][n + 1] = 0; // Same ^
C[m + 1][n + 1] = 1; // Zero-intialized except for [0][0] = 1
C[m + 1][n + 1] = 1; // Same ^
C[m + 1][n + 1]; // Uninitialized!


There are some contexts where arrays are zero-initialized anyway, but it doesn't hurt to do so explicitly.



Note that if you want to initialize with values other than zero, you'd be (mostly) out of luck. I've done work recently with template metaprogramming that would help...



// You can subclass this type, add it as a member, etc.
template<class T, T... I> struct Seq
typedef T value_type [sizeof...(I)];
// If you want to use it directly from here:
static constexpr value_type value = I...;
// Don't bother trying with any variation of...
// static constexpr value_type to_array(void) return I...;
;
template<class T, T... I0, T... I1>
auto operator+(Seq<T, I0...> const&, Seq<T, I1...> const&)
-> Seq<T, I0+I1...> return ;
template<class T, T... I0, T... I1>
auto operator<<(Seq<T, I0...> const&, Seq<T, I1...> const&)
-> Seq<T, I0..., I1...> return ;
// ... more Seq manipulation ...


I can use this to define ranges of numbers, binomial coefficients, etc. and as long as I still have some form of access to the template arguments, I can make an array of it. (That includes moving around a Seq<...> as an abstract T until the function where it's used.) I'd love to know what more can be done with this. I tried returning an initializer_list and defining an array out of that, but no luck (array initializers apparently only look like initializer_lists.)






share|improve this answer























  • okay but how do I complete the void freeLCSTable() function above?

    – Ayaan
    Nov 14 '18 at 4:51











  • Sorry, I'm not sure, and I'm not sure I answered the question looking at your code again. I work almost exclusively on the stack. It looks like you're assigning an array to a pointer that was already allocated, which would mean that the original is never freed and freeLCSTable would try to free the array that's on the stack. Hopefully someone with more dynamic memory experience could chime in.

    – John P
    Nov 14 '18 at 5:03















0














As long as you initialize part of the array, the rest will be default-initialized.



C[m + 1][n + 1] = 0; // Zero-initialized
C[m + 1][n + 1] = 0; // Same ^
C[m + 1][n + 1] = 1; // Zero-intialized except for [0][0] = 1
C[m + 1][n + 1] = 1; // Same ^
C[m + 1][n + 1]; // Uninitialized!


There are some contexts where arrays are zero-initialized anyway, but it doesn't hurt to do so explicitly.



Note that if you want to initialize with values other than zero, you'd be (mostly) out of luck. I've done work recently with template metaprogramming that would help...



// You can subclass this type, add it as a member, etc.
template<class T, T... I> struct Seq
typedef T value_type [sizeof...(I)];
// If you want to use it directly from here:
static constexpr value_type value = I...;
// Don't bother trying with any variation of...
// static constexpr value_type to_array(void) return I...;
;
template<class T, T... I0, T... I1>
auto operator+(Seq<T, I0...> const&, Seq<T, I1...> const&)
-> Seq<T, I0+I1...> return ;
template<class T, T... I0, T... I1>
auto operator<<(Seq<T, I0...> const&, Seq<T, I1...> const&)
-> Seq<T, I0..., I1...> return ;
// ... more Seq manipulation ...


I can use this to define ranges of numbers, binomial coefficients, etc. and as long as I still have some form of access to the template arguments, I can make an array of it. (That includes moving around a Seq<...> as an abstract T until the function where it's used.) I'd love to know what more can be done with this. I tried returning an initializer_list and defining an array out of that, but no luck (array initializers apparently only look like initializer_lists.)






share|improve this answer























  • okay but how do I complete the void freeLCSTable() function above?

    – Ayaan
    Nov 14 '18 at 4:51











  • Sorry, I'm not sure, and I'm not sure I answered the question looking at your code again. I work almost exclusively on the stack. It looks like you're assigning an array to a pointer that was already allocated, which would mean that the original is never freed and freeLCSTable would try to free the array that's on the stack. Hopefully someone with more dynamic memory experience could chime in.

    – John P
    Nov 14 '18 at 5:03













0












0








0







As long as you initialize part of the array, the rest will be default-initialized.



C[m + 1][n + 1] = 0; // Zero-initialized
C[m + 1][n + 1] = 0; // Same ^
C[m + 1][n + 1] = 1; // Zero-intialized except for [0][0] = 1
C[m + 1][n + 1] = 1; // Same ^
C[m + 1][n + 1]; // Uninitialized!


There are some contexts where arrays are zero-initialized anyway, but it doesn't hurt to do so explicitly.



Note that if you want to initialize with values other than zero, you'd be (mostly) out of luck. I've done work recently with template metaprogramming that would help...



// You can subclass this type, add it as a member, etc.
template<class T, T... I> struct Seq
typedef T value_type [sizeof...(I)];
// If you want to use it directly from here:
static constexpr value_type value = I...;
// Don't bother trying with any variation of...
// static constexpr value_type to_array(void) return I...;
;
template<class T, T... I0, T... I1>
auto operator+(Seq<T, I0...> const&, Seq<T, I1...> const&)
-> Seq<T, I0+I1...> return ;
template<class T, T... I0, T... I1>
auto operator<<(Seq<T, I0...> const&, Seq<T, I1...> const&)
-> Seq<T, I0..., I1...> return ;
// ... more Seq manipulation ...


I can use this to define ranges of numbers, binomial coefficients, etc. and as long as I still have some form of access to the template arguments, I can make an array of it. (That includes moving around a Seq<...> as an abstract T until the function where it's used.) I'd love to know what more can be done with this. I tried returning an initializer_list and defining an array out of that, but no luck (array initializers apparently only look like initializer_lists.)






share|improve this answer













As long as you initialize part of the array, the rest will be default-initialized.



C[m + 1][n + 1] = 0; // Zero-initialized
C[m + 1][n + 1] = 0; // Same ^
C[m + 1][n + 1] = 1; // Zero-intialized except for [0][0] = 1
C[m + 1][n + 1] = 1; // Same ^
C[m + 1][n + 1]; // Uninitialized!


There are some contexts where arrays are zero-initialized anyway, but it doesn't hurt to do so explicitly.



Note that if you want to initialize with values other than zero, you'd be (mostly) out of luck. I've done work recently with template metaprogramming that would help...



// You can subclass this type, add it as a member, etc.
template<class T, T... I> struct Seq
typedef T value_type [sizeof...(I)];
// If you want to use it directly from here:
static constexpr value_type value = I...;
// Don't bother trying with any variation of...
// static constexpr value_type to_array(void) return I...;
;
template<class T, T... I0, T... I1>
auto operator+(Seq<T, I0...> const&, Seq<T, I1...> const&)
-> Seq<T, I0+I1...> return ;
template<class T, T... I0, T... I1>
auto operator<<(Seq<T, I0...> const&, Seq<T, I1...> const&)
-> Seq<T, I0..., I1...> return ;
// ... more Seq manipulation ...


I can use this to define ranges of numbers, binomial coefficients, etc. and as long as I still have some form of access to the template arguments, I can make an array of it. (That includes moving around a Seq<...> as an abstract T until the function where it's used.) I'd love to know what more can be done with this. I tried returning an initializer_list and defining an array out of that, but no luck (array initializers apparently only look like initializer_lists.)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 4:46









John PJohn P

5131926




5131926












  • okay but how do I complete the void freeLCSTable() function above?

    – Ayaan
    Nov 14 '18 at 4:51











  • Sorry, I'm not sure, and I'm not sure I answered the question looking at your code again. I work almost exclusively on the stack. It looks like you're assigning an array to a pointer that was already allocated, which would mean that the original is never freed and freeLCSTable would try to free the array that's on the stack. Hopefully someone with more dynamic memory experience could chime in.

    – John P
    Nov 14 '18 at 5:03

















  • okay but how do I complete the void freeLCSTable() function above?

    – Ayaan
    Nov 14 '18 at 4:51











  • Sorry, I'm not sure, and I'm not sure I answered the question looking at your code again. I work almost exclusively on the stack. It looks like you're assigning an array to a pointer that was already allocated, which would mean that the original is never freed and freeLCSTable would try to free the array that's on the stack. Hopefully someone with more dynamic memory experience could chime in.

    – John P
    Nov 14 '18 at 5:03
















okay but how do I complete the void freeLCSTable() function above?

– Ayaan
Nov 14 '18 at 4:51





okay but how do I complete the void freeLCSTable() function above?

– Ayaan
Nov 14 '18 at 4:51













Sorry, I'm not sure, and I'm not sure I answered the question looking at your code again. I work almost exclusively on the stack. It looks like you're assigning an array to a pointer that was already allocated, which would mean that the original is never freed and freeLCSTable would try to free the array that's on the stack. Hopefully someone with more dynamic memory experience could chime in.

– John P
Nov 14 '18 at 5:03





Sorry, I'm not sure, and I'm not sure I answered the question looking at your code again. I work almost exclusively on the stack. It looks like you're assigning an array to a pointer that was already allocated, which would mean that the original is never freed and freeLCSTable would try to free the array that's on the stack. Hopefully someone with more dynamic memory experience could chime in.

– John P
Nov 14 '18 at 5:03

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293132%2finitialize-two-2d-arrays-and-fill-the-first-column-and-first-row-of-one-of-the-a%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto