Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q 1 : Write a C + + function that takes an array as a parameter. The function should create and return a new dynamic

Q1: Write a C++ function that takes an array as a parameter. The function should create and return a new dynamic array that is double the size of the original array.Side Note: I understand that regular static arrays cannot be used to complete the task in Q1 unless the sizes are defined using fixed constant values. Initially, I asked ChatGPT if it was possible to complete Q1 using static arrays without constants for the sizes, and it responded affirmatively, even providing the following incorrect code snippet:// Define the new array size as double the original array sizeint newSize =2* originalSize;// Declare the new array with double the size of the original arrayint newArray[newSize];I then asked, 'Did something change about C++? Can we now use variables to define the size of static arrays?'ChatGPT clarified: In C++, the size of an array must be a compile-time constant. You cannot use a variable to define the size of a static array directly because the array size needs to be known at compile time for the compiler to allocate the appropriate amount of memory.The Point: DO NOT TRUST CHATGPT. Q2: Using a pen and paper, illustrate and compare pointers and references in C++. No typing allowed. Draw a memory stack depicting memory locations and demonstrate how pointers and references function. take a picture for your answer and post it in a word document and upload it.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions