Recursion 2048 https://online.codingblocks.com/player/5104/content/387?s=638

Why did we take 2d char array if we are printing only in 1d array? I didn’t understand

post the link of the question here

It was not a question. My doubt was in the video lecture

can understand your line
“” when we are printing in 1d array"""
can u elaborate

In that code. sir has taken spelling[ ][10] array whereas when printing he writes spelling[n%10]. So, this 2d to 1d transformation. I didn’t understand. Why did we even choose 2d at the first place?

look i think he wants to print the spelling at n%10 index in 2d char array the first index behave as a pointer which is pointing to all column therefore if 2d array store like this
A B C D
E F G H
I J K L
M N O P
Q R S T
then if n is 3 then spelling [3%10] it cout the whole MNOP
if u didnt get it then post the code i will check and then reply

sorry, it was not like that.
he wrote spelling[ ][10]={“one”, “two”,…“nine”};
whereas while print he wrote spelling[n%10];
Please check this

it is the same i wrote just the way of representing is different.
In this if u cout spelling [0] then one will be the output .
“one” is itself an array that is 1 d array as i said earlier that spelling[n%10] act as a pointer or u can sa the row number it will cout all the charater present at that row
in this 2d array many 1d array are stored(ex one two three etc)
if u cout spelling[0][0] then o will be output ans simplly spelling [0] the whole one wiil be cout

hope this help

1 Like

Oh right! I misunderstood it. It would have been better if we had taken a 1d array of strings.

yes
string spelling[]
also works

1 Like