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 4617118
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:04:46+00:00 2026-05-22T02:04:46+00:00

Hey there, I have a probably straight-forward question about the following problem: I have

  • 0

Hey there,
I have a probably straight-forward question about the following problem:

I have a function

double afunction(double *myarray)
{   
    double ret = 1.0;
    for(int i = 0; i < 4; i++)
        ret *= myarray[i]*myarray[i];
    return ret;
}

Now I want to modify it so that I pass two new parameters: int index describing which index of myarray to change like the following: myarray[ index ] = *add;. This would be the following:

double afunction(double *myarray, int index, double *add)
{   
    myarray[ index ] += *add;
    double ret = 1.0;
    for(int i = 0; i < 4; i++)
        ret *= myarray[i]*myarray[i];
    return ret;
}

The problem is: I don’t want to modify the array myrray and I don’t want to create a new array for this because of memory-regards (this will later be computed on the GPU and there I couldn’t allocate a whole new array in a kernel function anyway.
Easy solution to this?
Thanks!

EDIT
Sorry, I mistyped something. Instead myarray[ index ] = *add; I meant to say myarray[ index ] += *add;

EDIT2
Example of a bigger function which could later on easily be extended to about 50 different return-cases. So to have the if-statement to modify the certain value myarray[index] with adding *add in each return-case is pretty ugly 🙁

double afunction(double *myarray, int funcIndex, int indexAdd, double *add)
{   
    myarray[ indexAdd ] += *add;

    if(funcIndex >= 1 && funcIndex <= 4)
        return myarray[1]*myarray[1]*myarray[2];

    switch(funcIndex)
    {
        case 5:
            return sin(myarray[3]) * cos(myarray[1]);
        case 6:
            double ret = exp(myarray[1]);
            for(int i = 1; i < 5; i++)
                ret *= (myarray[ i ]-myarray[ 5-i ]);
            return ret;
        case 7:
            double ret = 0.0;
            for(int i = 1; i < 10; i++)
                ret += myarray[ i ];
            return ret;
    }

    return 0.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-05-22T02:04:47+00:00Added an answer on May 22, 2026 at 2:04 am
    double afunction(double *myarray, int index, double *add)
    {   
        double ret = (*add) * (*add);
        for(int i = 0; i < 4; i++)
            if( i != index )
                ret *= myarray[i]*myarray[i];
        return ret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey there I have 2 tables with each multiple columns and i want to
Hey there, so far i have this, it toggles my footer down and up,
Hey, I have 10 ul.rating elements on my page. I want to refresh those
Hey guys, I currently have a root table view which has a toolbar at
hey guys, my ie source code of an image says this: <img width=1500 src=something.jpg
In my application we will present the video stream from a traffic camera to
I just finished what I would call a small django project and pretty soon
I'm starting to wonder if this is even possible. I've searched for solutions on
This is unfortunately defined in some external library: cannot touch! // library.h typedef struct
I am using windows 7 64 bit with MSVC2005 and QT (but I doubt

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.