Question

Write a function that takes a size, creates a new array of that size with all zeros, and returns the array. If the size is no

#include <iostream>
using namespace std;


int * newZeroArray(int size) {
        //your code here
}

int main() {
        int size = 10;
        int * A = newZeroArray(size);

        for(int i = 0; i < size; i++)
                cout << A[i] << " ";
        cout << endl;
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Given below is the completed code. Please do rate the answer if it helped. Thankyou.
#include <iostream>
using namespace std;


int * newZeroArray(int size) {
if(size <= 0)
return nullptr;
else{
int *arr = new int[size];
for(int i = 0; i < size; i++)
arr[i] = 0;
return arr;
}
}

int main() {
int size = 10;
int * A = newZeroArray(size);

for(int i = 0; i < size; i++)
cout << A[i] << " ";
cout << endl;
}

output
---
0 0 0 0 0 0 0 0 0 0

Add a comment
Know the answer?
Add Answer to:
#include <iostream> using namespace std; int * newZeroArray(int size) { //your code here } int main()...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT