Consider these legal C++ declarations: char str[100] = This is a simple C-string; const char *pstr...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider these legal C++ declarations: char str[100] = "This is a simple C-string"; const char *pstr = "This is a declaration of a pointer to a C-string"; char *qstr = const_cast<char *> (pstr); char *rstr = str; Would the following be legal? Solve alone first, then discuss with your group and test using a compiler so that you fully understand what is going on. Write up your conclusions and submit them in an email with all the names of your group on it. Attach your test program and its output. For each of the following questions, start over at the original declarations and values given above. Can we change: str[10] to a new value? pstr [10] to a new value? pstr to a different string? str to a different string? // these last two questions are a bit tricky - think how you can interpret them If so, how, and if not, why not? If we change pstr to point to a different string: pstr = "Hello"; what happens to qstr? Will qstr then point to the old string or the new string? Can we assign str = "Goodbye"; Why or why not? If we change rstr[5], what happens to str? If we change str[10], what happens to rstr? What happens if you print pstr, *pstr, or (void *)pstr? Then (AFTER agreeing on your answers), using str-ptr.cpp as a guide, print out the addresses of the variables and the data they point to, and try these things in the program. What conclusions can you draw from the results? Particularly, can you work out why things do not work? If you have any questions, show me your code and the conclusions you have drawn from it. If you Consider these legal C++ declarations: char str[100] = "This is a simple C-string"; const char *pstr = "This is a declaration of a pointer to a C-string"; char *qstr = const_cast<char *> (pstr); char *rstr = str; Would the following be legal? Solve alone first, then discuss with your group and test using a compiler so that you fully understand what is going on. Write up your conclusions and submit them in an email with all the names of your group on it. Attach your test program and its output. For each of the following questions, start over at the original declarations and values given above. Can we change: str[10] to a new value? pstr [10] to a new value? pstr to a different string? str to a different string? // these last two questions are a bit tricky - think how you can interpret them If so, how, and if not, why not? If we change pstr to point to a different string: pstr = "Hello"; what happens to qstr? Will qstr then point to the old string or the new string? Can we assign str = "Goodbye"; Why or why not? If we change rstr[5], what happens to str? If we change str[10], what happens to rstr? What happens if you print pstr, *pstr, or (void *)pstr? Then (AFTER agreeing on your answers), using str-ptr.cpp as a guide, print out the addresses of the variables and the data they point to, and try these things in the program. What conclusions can you draw from the results? Particularly, can you work out why things do not work? If you have any questions, show me your code and the conclusions you have drawn from it. If you
Expert Answer:
Answer rating: 100% (QA)
Lets analyze each of the scenarios involving the given C declarations step by step Can we change str10 to a new ... View the full answer
Related Book For
Managing Operations Across the Supply Chain
ISBN: 978-0078024030
2nd edition
Authors: Morgan Swink, Steven Melnyk, Bixby Cooper, Janet Hartley
Posted Date:
Students also viewed these accounting questions
-
To prepare and make sure that you fully understand what a psychological autopsy is, find a newspaper story in which a psychological autopsy was performed. Summarize the news story and discuss how the...
-
Discuss with your group a specialty in the accounting profession ie forensic public accounting auditing etc Decide on one and research it Produce a 700word paper or 16slide presentation using a...
-
In general, this is a simple case to use for illustrating logistics role in a successful lean system. To begin, it is useful to start by providing the class with some information about Lear...
-
Find the number density N/V for electrons such that (a) e -a = 1 and (b) e -a = 10 -6 .
-
Suppose that a college town has a large number of firms selling a homogeneous productpizzaand that there are two types of consumers in the town. The towns permanent residents are fully informed about...
-
Crane Corporation, which uses straight-line depreciation and amortization, incurred the following costs in 2026: Acquisition of R&D equipment with a useful life of 4 years in R&D projects (no...
-
Why is the evaluation of a projects success or failure somewhat subjective?
-
Selected accounts from the chart of accounts of Mercer Company are shown below. 101 Cash ............401 Sales Revenue 112 Accounts Receivable .......412 Sales Returns and Allowances 120 Inventory...
-
Do you think engaging fans through social media is an effective marketing strategy for sports and entertainment celebrities and businesses? Why or why not? Cite an example of engaging as a fan from...
-
The Summit at Crystal Mountain is a small ski resort located just outside Mount Rainier, Washington; approximately 100 miles from Seattle. The resort consists of slopes that appeal to skiers of...
-
Prepare a food department income statement in proper format for the Mid- lands Restaurant from the following information for the first quarter ended on March 31, year 0004 (other income was received...
-
Prove that the identity \(\sigma^{2}=\mu_{2}^{\prime}-\mu^{2}\) holds for any probability density for which these moments exist.
-
If a random variable has the standard normal distribution, find the probability that it will take on a value (a) between 0 and 2.3 ; (b) between 1.22 and 2.43 ; (c) between -1.45 and -0.45 ; (d)...
-
The nozzle of a mixing vibrator is tested for its number of vibrations. The vibration frequency, for each nozzle sample, can be modeled by a normal distribution with mean 128 and standard deviation...
-
In order to test the durability of a new paint, a highway department had test strips painted across heavily traveled roads in 15 different locations. If on the average the test strips disappeared...
-
If a random variable has the standard normal distribution, find the probability that it will take on a value (a) less than 1.75 ; (b) less than -1.25 ; (c) greater than 2.06 ; (d) greater than -1.82 .
-
3.) An 8-H inductor is connected in series with an 800-F capacitor. The capacitor is connected back to the inductor to form a complete circuit. The wires have negligible resistance. Initially, there...
-
From the choice of simple moving average, exponential smoothing, and linear regression analysis, which forecasting technique would you consider the most accurate? Why? please write it in word...
-
Figure illustrates the analogy of a boat hitting rocks as the level of waterfalls. Why is water a good analogy for inventory? Is the sequence in which rocks are encountered a good way to prioritize...
-
Based on the BOM in problem 4, what is the cumulative lead time for end item A?
-
1. How would you describe the team members morale at this point? What are their primary concerns? 2. Given the team members comments, what advice would you give Roger Terry regarding the double-block...
-
Randomly list the 10 examples you identified, keeping the rationale for each hidden. Exchange lists with another group. Each group should discuss the list given to it by the other group and classify...
-
Identify at least five products or brands that probably could not use that strategy. Develop a clear rationale to support each example. Heineken is the second-largest brewer in the world, with sales...
-
Identify at least five products or brands you are familiar with that could use the same three-step approach perfected by Heineken for entering foreign markets. Develop a clear rationale to support...
Study smarter with the SolutionInn App