Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8608707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:41:11+00:00 2026-06-12T03:41:11+00:00

here is my code and im not allowed to use a loop in the

  • 0

here is my code and im not allowed to use a loop in the subarray function im pretty confused maybe someone can point me in the right direction i feel like im almost there..

int *duplicateArray(int *arr, int size) 
{
int *newArray;

if (size<=0)
    return NULL;

newArray = new int[size];

for (int index=0;index<size;index++)
    newArray[index]=arr[index];

return newArray;
}

int* subArray(int *sub, int start, int length)
{

 int aa[10]={1,2,3,4,5,6,7,8,9,10};
 int *dup;
 dup = aa;
 duplicateArray(dup,10);
 return dup;


}

int main()
{   cout << "Testing subArray: " << endl 
         << "Expected result: 5, 6, 7, 8 " << endl;
int *subArr;
int start = 5;
subArr = subArray(subArr, 5,4);
for (int index = start; index<10; index++)
    cout << subArr[index];
delete [] subArr;
subArr = 0;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:41:13+00:00Added an answer on June 12, 2026 at 3:41 am

    So, since this is homework, I’m going to avoid posting a solution directly. You say that;

    im not allowed to use a loop in the subarray function

    Yet, currently, subArray calls duplicateArray, which uses a loop. This seems to be in conflict with the spirit of the requirement.

    Since you haven’t said otherwise, I’m assuming that subArray should duplicate the contents of its argument between start and the end. So, what do we know?

    We know that the size of the returned array should be length - start elements. We also know (well, perhaps) that a function named memcpy exists which allows you to copy a block of bytes from one place to another (assuming they do not overlap).

    (note that I am suggesting memcpy here because we are dealing with POD types (Plain Old Data) and because I doubt your class has delved into the STL. In the future you will be better served by something like std::copy(), but for now this is ok)

    So, in order, we need to:

    1. Declare a new array to return with length - start elements. You must dynamically allocate this array! Currently you are returning a pointer to a locally declared array. That pointer becomes invalid as soon as the function returns.

    2. Copy length - start elements (elements, not bytes! Make sure to take into account the number of elements as well as the size of an individual element) from sub + start into this new array.

    3. Return the new array (pointer really).

    If I have somehow violated the requirements or intent of your assignment then you need to elaborate on your problem for me. Currently there is not much to go on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code is not running on .click when I have this: $(.cancel).click(function() { alert(got here);
What's the proper syntax here? If (@timestamp < (Select PromoStartTimestamp From @promo)) RAISERROR('Code not
What am I doing wrong here? Declare @starttimestamp datetime = getdate(); RAISERROR(N'Code not valid
Here's my code that is not working: print To: ; my $to=<>; chomp $to;
Got this line of code here but its not working. private void Button_Click(object sender,
I have some code here which works perfectly in firefox but not in chrome
I have a piece of code here that does not work despite me using
Here is the code i was trying.I could not comprehend the output i got.Why
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here's the code for a simple page I have that is not working: <head>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.