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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:24:42+00:00 2026-05-13T16:24:42+00:00

For a 4-D array, I’m trying to average the values using compact pointer notation.

  • 0

For a 4-D array, I’m trying to average the values using compact pointer notation. Using examples from my text, it says I can use something like this:

void DisplayAverage(double (*set)[DIM1][DIM2][DIM3])
    double *ptr;
double subTotal2 = 0; 
    for (ptr = (double *)set; ptr < (double *)set + DIM0 * DIM1 * DIM2 * DIM3; ptr++) {
    subTotal2 += *ptr;
    subTotal2 /= (DIM0 * DIM1 * DIM2 * DIM3); 
cout << "Using compact pointer operations, total: " << subTotal2 << "\n";
    }
}

That code works. However, if I try to use another notation from the text:

for (ptr = (double *)set; ptr < (double *)(&set + 1); ptr++) {

to access the array, I get no output. Any thoughts? Thanks.

  • 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-13T16:24:42+00:00Added an answer on May 13, 2026 at 4:24 pm

    You have one address-of too much:

    // notice: "set" instead of "&set"
    for (ptr = (double *)set; ptr < (double *)(set + DIM0); ptr++) {
    

    You were adding one to the address of your parameter (and thus were pointing to nowhereland), instead of DIM0 to the value of your parameter (which will bring you to after the array data, which is your goal).

    Notice that the parameter is a pointer to an array of dimensions [DIM1][DIM2][DIM3]. In other words, the argument you pass to the function can be an array of type double[DIM0][DIM1][DIM2][DIM3], which will decay to the pointer type of that parameter. You have DIM0 rows, so you add DIM0 to that pointer to reach the position after the last cell.

    What you were probably having in mind was adding one to the pointer to the whole array. This will work if you have the following declaration, instead.

    void DisplayAverage(double (*set)[DIM0][DIM1][DIM2][DIM3]);
    

    You now need to pass the argument using &arg instead of just arg, to actually pass the address of the array, instead of letting it decay to its inner dimension type. The loop can then be written as

    for (ptr = (double *)set; ptr < (double *)(set + 1); ptr++) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 436k
  • Answers 436k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Nope, this is not possible. It's possible only to access… May 15, 2026 at 3:47 pm
  • Editorial Team
    Editorial Team added an answer To demonstrate, I'm going to invent the scenario that you're… May 15, 2026 at 3:47 pm
  • Editorial Team
    Editorial Team added an answer You could create a bootstrapper application. The application would install… May 15, 2026 at 3:47 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.