Question

In: Computer Science

. Consider the character array as follows: char mySentence[] = "Hello World!"; The number of characters...

. Consider the character array as follows:

char mySentence[] = "Hello World!";

The number of characters in the array can be determined by application of the strlen() function. Therefore, the end of the array can be determined by pointer arithmetic as follows:

char * endArray = mySentence + strlen(mySentence);

Now that the end of the array has been determined, utilise pointers in C++ to output each character in array in reverse and display it to the console window.

What other techniques could be utilised to achieve the same result? Hint: The below lines of code can be used to output the last character in the mySentence[] array once the endArray pointer has been assigned to the last element of the mySentence[] array:

char mySentence[] = "Hello World!";

char * endArray = mySentence + strlen(mySentence);

cout << (char)*(endArray - 1) << endl;

Solutions

Expert Solution


Related Solutions

in C programming language char character [100] = "hello"; a string array variable It is given....
in C programming language char character [100] = "hello"; a string array variable It is given. By writing a function called TranslateString, By accessing the pointer address of this given string, returning the string's address (pointer address) by reversing the string Write the function and use it on the main function. Function void will not be written as. Return value pointer address it will be. Sweat operation on the same variable (character) It will be made. Declaration of the function...
You need a data structure that contains fields for name (char array), color (char array), age...
You need a data structure that contains fields for name (char array), color (char array), age (int), and height (int). Name the struct Info when you define it. Create a function named getUserInfo() that asks the user for name, color, age, and height and then returns a data structure containing that information. It should do the following: What is your name? George What is your favorite color? Green What is your age? 111 What is your height in inches? 72...
6. Given the following array of characters: REALITYSHOWShow how this array will be sorted with the...
6. Given the following array of characters: REALITYSHOWShow how this array will be sorted with the help of : (a) insertion sort; (b) selection sort; (c) bubble sort with swaps counting; (d) bubble sort without swaps counting subject design and analysis of algorithms answer should be like eg p u r p l e p r u p l e
C++: How are std::cout << “hello world” and std::cout << “hello” << ‘ ‘ << “world”...
C++: How are std::cout << “hello world” and std::cout << “hello” << ‘ ‘ << “world” different?
In C++ please modify the following program and add characters (char) and names (strings) to be...
In C++ please modify the following program and add characters (char) and names (strings) to be added to the linked list along with integers. The current demo program accepts only integer data, so you would ask the user to select the data type to be added to the linked list. The user should be given the following three choices: (a) whole numbers (b) single characters (c) strings Once the user makes a selection from the list above then your program...
A password is a string of ten characters, where each character is a lowercase letter, a...
A password is a string of ten characters, where each character is a lowercase letter, a digit, or one of the eight special characters !, @, #, $, %, &, (, and ). A password is called awesome, if it contains at least one digit or at least one special character. Determine the number of awesome passwords.
For this question, a block is a sequence of 20 characters, where each character is one...
For this question, a block is a sequence of 20 characters, where each character is one of the 26 lowercase letters a-z. For example, these are blocks: iwpiybhunrplsovrowyt rpulxfsqrixjhrtjmcrr fxfpwdhwgxtdaqtmxmlf How many different blocks are there? A block is squarefree if no character appears two times consecutively. The first and third example above are squarefree, but the second example is not because of the two consecutive occurrences of r. How many squarefree blocks are there? A block is non-local if...
Nathan the Wise Discuss the assumptions of the characters of Nathan the Wise. Choose one character...
Nathan the Wise Discuss the assumptions of the characters of Nathan the Wise. Choose one character from each group to discuss. Group A: Discuss the superstition that the character has and how the character learns the superstition is groundless. Group A: Daja, Recha, Curd. Group B: Discuss the gossip, rumors and lies that the character uses, how the character uses the information, and how it affects other characters. Group B: Al-Hafi, the friar, and the patriarch. Group C: Discuss the...
Design an algorithm that will read an array of 200 characters and display to the screen...
Design an algorithm that will read an array of 200 characters and display to the screen a count of the occurrences of each of the five vowels (a, e, i, o, u) in the array. Your string is: The quick brown fox jumped over the lazy dog That is the question for my pseudo code question, I don't know if I have this correct can i have someone look this over and finish this and explain what i needed to...
In all cases we have an array of int or char of some fixed size. The...
In all cases we have an array of int or char of some fixed size. The program will prompt the user to enter some values, such as: Enter 7 integers to be stored in the array: 5 13 8 5 1 2    The questions that could then be asked of this data might be: Count how many numbers are < the last element Count how many numbers are odd Similarly we might prompt for character input: Enter 7 characters...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT