Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider these legal C++ declarations: char str[100] = This is a simple C-string; const char *pstr = This is a declaration of a pointer
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 (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
Step by Step Solution
★★★★★
3.39 Rating (149 Votes )
There are 3 Steps involved in it
Step: 1
Lets analyze each of the scenarios involving the given C declarations step by step Can we change str10 to a new ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started