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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:57:45+00:00 2026-05-30T14:57:45+00:00

My issue is the following: I am making a pointer to a dynamic two

  • 0

My issue is the following: I am making a pointer to a dynamic two dimensional array on the heap. This is done in a subfunction “Production” which fills in the elements of the table (array) and returns the pointer of the array to the main(). There I want to give the pointer as a parameter for another function “PrintTable”; which cout’s the table. My issue is that the returned pointer is actually a one dimensional array (c++) and I don’t know how to adress it to get the second row of the array..
Let me try to explain it to you:

So first I have a function which returns a pointer to a two-dimensional array.

int* Production(int num1, string name1[], int num2, string name2[])
{

int** productionTable=new int*[num1];
for (int i = 0; i < num1; i++)
{
      productionTable[i] = new int[num2];
}


for (int i=0;i<num1;i++)
{
cout << "\nGive production " << name1[i]<<endl;
for (int j=0;j<num2;j++)
{
    cout << "On " << name2[j] << " : ";
    cin >> productionTable[i][j];
}
}
return* productionTable;
}

in the main () I let the returned pointer point to a pointer productiontable so it exists in the main.

int* productionTable=Production(num1, name1[], num2, name2[])

Then I call function printTable() witch has to output the 2dimensional array as a table. so I want to use this pointer as an argument for another function; to cout the elements from this array.

PrintTable(num1, name1[], num2, name2[], productionTable);

This function looks like this:

void printTable(int num1, string name1[], int num2, string name2[],int* productionTable)
{
cout << left <<setw(10)<< "";
for (int i=0;i<num2;i++)
{
    cout << left <<setw(10)<< name2[i];
}
cout<<endl;
for (int i=0;i<num1;i++)
{
cout << setw(10)<<name1[i]<<"";
for (int j=0;j<num2;j++)
{
    cout << left <<setw(10)<< productionTable[i+j];

}cout<<endl;
}
}

My problem is that I can’t get the function to output the second row right. How should i adress the second parameter of the array. So far i’ve read i should make the table point to [COLindex * COL_size + ROWindex]. I’ve tried it but i dan’t get him to print the second row. What should the COL_size paramter be?

  • 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-30T14:57:47+00:00Added an answer on May 30, 2026 at 2:57 pm

    This is your problem:

    int** productionTable=new int*[num1];
    ...
    return* productionTable;
    

    Basically, by the return, you return only the first row (or a pointer to it) discarding the rest of the table. To make it work, you could declare Production and productionTable (at all places) as int**, return productionTable in Production and use productionTable[i][j] for element retrieval.

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

Sidebar

Related Questions

I have the following issue related to iterating over an associative array of strings
I'm following this tutorial attempting to learn XNA, but I'm having issues making my
I'm having a jQuery issue which is making debugging JavaScript more of a bitch
I'm following this tutorial on making an animation like IKEA: http://static.buildinternet.com/live-tutorials/interactive-picture/index.html The issue I'm
The following issue popped up in my open source library, and I can't figure
I have the following issue using java 1.4 I try to display a very
I have the following issue and I would like to know what exactly happens.
I've the following issue I've a windows application It calls a remote web service
I am having following issue with reading binary file in C. I have read
I have the following issue with a UTF8 files structured as following: FIELD1§FIELD2§FIELD3§FIELD4 Looking

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.