2. [30pts] Write the code necessary to properly allocate memory (on the heap) in the following scenarios a). An array arr of k integers b) A string str of length p c) An n x m matrix mat of integers initialized to zeros Answer a). a = (char *)malloc(sizeof(char) * n); 1. [30 pts] Match the items on the left with the memory segment in which they are stored. Answers may be used more than once, and more than one answer may be required. 1. Static variables 2. Local variables 3. Global variables 4. Constants 5. Machine Instructions 6. malloc() 7. String Literals Answer A. Code B. Static C. Heap D. Stack

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter9: Completing The Basics
Section9.6: A Closer Look: Namespaces And Creating A Personal Library
Problem 3E: (For thought) a. What’s an advantage of namespaces? b. What’s a possible disadvantage of namespaces?
icon
Related questions
Question
2. [30pts] Write the code necessary to properly allocate memory (on the heap) in the following
scenarios
a). An array arr of k integers
b) A string str of length p
c) An n x m matrix mat of integers initialized to zeros
Answer
a). a = (char *)malloc(sizeof(char) * n);
Transcribed Image Text:2. [30pts] Write the code necessary to properly allocate memory (on the heap) in the following scenarios a). An array arr of k integers b) A string str of length p c) An n x m matrix mat of integers initialized to zeros Answer a). a = (char *)malloc(sizeof(char) * n);
1. [30 pts] Match the items on the left with the memory segment in which they are stored. Answers
may be used more than once, and more than one answer may be required.
1. Static variables
2. Local variables
3. Global variables
4. Constants
5. Machine Instructions
6. malloc()
7. String Literals
Answer
A. Code
B. Static
C. Heap
D. Stack
Transcribed Image Text:1. [30 pts] Match the items on the left with the memory segment in which they are stored. Answers may be used more than once, and more than one answer may be required. 1. Static variables 2. Local variables 3. Global variables 4. Constants 5. Machine Instructions 6. malloc() 7. String Literals Answer A. Code B. Static C. Heap D. Stack
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
CMPTR
CMPTR
Computer Science
ISBN:
9781337681872
Author:
PINARD
Publisher:
Cengage
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,