Hello, i was given a project to do on c++, i was supposed to write a cpp code that would reverse a *char element(word) leaving the last letter as it is, say, "12345" would be "43215".
Can you please explain what the use of the void print(char*str) function and its contains. I need to explain this code to my teacher but i stuttered on this part. Thanks inadvance.
You need to explain to your teacher. That both shows what you understand and helps you to understand. We cannot set knowledge into your head, but we can give you some questions to ponder.
I presume that you have not run the program to see what happens?
Where is that function used? Does that in any way correlate with what you see the program to do?
1 2 3 4 5 6 7 8 9
void print(char*str)
{
for (int i = 0; i < strlen(str); i++)
{
cout << *(str + i);
}
cout << endl;
}
What is in the function?
Is there a loop? If yes, how many times does it repeat? What happens in the body of the loop?
All i ask for is to explain in detail what every line is responsible for, i have written half of this code and gotten help from somebody else but from his explanation he told me that it enables to print in the first line. I have ran this program and it works perfectly fine. User inputs a word, it returns the inputted word and then the reversed word but the last letter stays the same, 'hello12345' to '4321olleh5'.
Alright, let me get this straight, i haven been given this project to do, i wrote what i could and went to the academy i learn in and asked for an extra lesson, a new teacher was appointed for me and with his help we finished the project, he helped me by putting the for loop into the void print function which i didn't know anything about (our teacher didn't teach us anything about it). I have understood every single line in this cpp code except the line where the function voidprint(char*str) is declared.
no need to come at me as if i cheat or anything, i deliberately didn't include background on the project to get the solution as short and quick as possible.