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...
C Implement the function Append (char** s1, char** s2) that appends the second character array to...
C Implement the function Append (char** s1, char** s2) that appends the second character array to the first, replaces the first array with the result and replaces the second character array with the original first array. For example, if the first character array is "hello" and the second is "world" at the end of the function the new value of the first character array should be"helloworld" and the second array should be "hello". If the input is invalid 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...
for C program 10 by 10 char array. char 0-9 as rows and char a-j as...
for C program 10 by 10 char array. char 0-9 as rows and char a-j as collumns.
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?
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
QUESTION 1 The statement char ch = ‘A’ would store in ch A. The character A...
QUESTION 1 The statement char ch = ‘A’ would store in ch A. The character A B. ASCII value of A C. A along with the single inverted commas D. Both (a) and (b) 2 points    QUESTION 2 Which of the following scanf() statement will you use to accept following variables? float gravity_a; double gravity_b; A. scanf("%f %lf", &gravity_a, &gravity_b); B. scanf("%LF %f ", gravity_a, gravity_b); C. scanf("%LF %LF ", &gravity_a, &gravity_b); D. scanf("%f %LF ", gravity_a, gravity_b); 2...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT