please explain how the statements in the for loop as given in the video are executing by giving a dry run as Im not able to understand
About the phone keypad
string ch[10]= { " ", ".+@$", "abc", "def", "ghi", "jkl" , "mno", "pqrs" , "tuv", "wxyz" };
void keypad(string str,int i, char out[] , int j ){
if(i == str.size()){
out[j] = '\0';
cout << out <<endl;
return ;
}
int digit = str[i]-'0';
if(digit == 0 || digit == 1)
return keypad(str, i +1 , out , j);
for(int k = 0 ; ch[digit][k] != '\0'; k++){
out[j] = ch[digit][k];
keypad(str , i+1 , out , j+1);
}
return;
}
eg : 23
k = 0
out[j] = a
calls keypad( i+1 , j+1 ) shift in both i/p and output array
k = 0 digit = 3
out[1]= d
calls keypad( 2, 2) base condition is hit -> prints ad
then goes back to
condition when k =1 digit =3 and in = 1 out = 1
ch[3][1]-> e
calls in = 2 , j = 2
hits base condition
printes ae
goes back
k =2
ch[3][2] -> f
calss i = 2 j = 2
prints af
k = 3 ch[3][3] == null
returns to
state k =1 digit =2 i = 0 j = 0
puts into output b
then calls i+1 , j+1
digit = 3
…
and sooo on