+ 2

What i should count to last word in the string if i counting from last , -1 , -0 or 1.

here is the code let myName = "Rocket Racoon"; so what i will count to 'n' in the last of strign.

20th Apr 2019, 4:24 AM
Bug Slayer
2 Réponses
+ 1
U can definitely not use 1. It is out of our options. Now, u must know that this is stored as an array of characters, with proper index numbers, I. E, R has index number 0, o has index number 1 and so on. So, I guess u know why 1 is out. Now, u can use -0. Then the loop will be like (assuming n is the index of the last letter, before the null character (\0)) for(; n >= -0; n--) cout myName [n]; Because the first character has index 0. For using -1, everything will be same except the condition. It would be, clearly enough, n > -1. Try to run this. I hope it helps 😊😊
20th Apr 2019, 3:20 PM
Bibaswan Roy
Bibaswan Roy - avatar
+ 1
Sorry I wrote for c++ ... But u get my point, right?
20th Apr 2019, 3:37 PM
Bibaswan Roy
Bibaswan Roy - avatar