I am trying to initialize a 2d array (matrix) to 0 but, cant do it:
int longestCommonSubsequence(string text1, string text2) {
int len1=0;
len1=text1.length()+1;
int len2=0;
len2=text2.length()+1;
int dp[len1][len2]={0};
Error:
Line 8: Char 16: error: variable-sized object may not be initialized
int dp[len1][len2]={0};
^~~~
1 error generated.
I want initialize the matrix while declaring it. I do not want to use for loop.
int dp[len1][len2]={0};is not allowed. Usestd::vectorint dp[len1][len2];did compile without error, then you are using a compiler extension. If you want to stay with it you need to read your compilers manual. However, its not really recommended, rather aim to write portable code