6. Consider the following C function: char *copy(char * s) { /* Returns a string containing the first 10 characters of the argument. */ char ret [10]; for (int i = 0; i < 10%; i++) { } } ret [i] = s[i]; return ret; (a) [5] Identify the two issues related to pointers and memory management that may cause problems when this function is used in a program. (b) [5] Explain how to fix the issue related to memory management.
6. Consider the following C function: char *copy(char * s) { /* Returns a string containing the first 10 characters of the argument. */ char ret [10]; for (int i = 0; i < 10%; i++) { } } ret [i] = s[i]; return ret; (a) [5] Identify the two issues related to pointers and memory management that may cause problems when this function is used in a program. (b) [5] Explain how to fix the issue related to memory management.
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 1TF
Related questions
Question
![6.
Consider the following C function:
char *copy(char * s) {
/* Returns a string containing the first 10 characters of the argument. */
char ret [10];
for (int i = 0; i < 10%; i++) {
}
}
ret [i] = s[i];
return ret;
(a) [5] Identify the two issues related to pointers and memory management that may cause
problems when this function is used in a program.
(b) [5] Explain how to fix the issue related to memory management.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F10eebb53-c222-4ba4-91a2-e54084fe388d%2Fa4ef00f4-c8ef-4bdb-b28e-44a51a6c0b1f%2Foi7r6hf_processed.png&w=3840&q=75)
Transcribed Image Text:6.
Consider the following C function:
char *copy(char * s) {
/* Returns a string containing the first 10 characters of the argument. */
char ret [10];
for (int i = 0; i < 10%; i++) {
}
}
ret [i] = s[i];
return ret;
(a) [5] Identify the two issues related to pointers and memory management that may cause
problems when this function is used in a program.
(b) [5] Explain how to fix the issue related to memory management.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,

New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage