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

  • Home
  • SEARCH
  • 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 9128905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:37:32+00:00 2026-06-17T07:37:32+00:00

I would like to have an array int candidates[9][] where the first dimension is

  • 0

I would like to have an array int candidates[9][] where the first dimension is known (9) and the second, depends on the execution.

I found that a method to allocate the array was the following:

int *candidates[9]; /* first allocation at declaration */
for(int i=0;i<9;i++) candidates[i] = new int[6]; /* allocation at execution */

but when I use it like that, and I try to access to candidates[i][j], it doesn’t work. I initialize candidate[i] with a function fun() that return and int[] of the right size, but the content of candidate[i][j] is wrong.

candidates[0] = fun();

I don’t understand where I am wrong… Thank you for your help 🙂

  • 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-17T07:37:34+00:00Added an answer on June 17, 2026 at 7:37 am

    Why dont you try vector template class from STL…code is more neater and comprehensive…

    #include <iostream>
    #include <vector>
    
    using namespace std;
    
    int main()
    {
        vector<int> arrayOfVecs[9];
    
        //use each array to put as many elements you want, each one different
        arrayOfVecs[0].push_back(1);
        arrayOfVecs[1].push_back(100);
        .
        .
        arrayOfVecs[1].push_back(22);
        arrayOfVecs[0].pop_back();
        arrayOfVecs[8].push_back(45);
    
        cout<<arrayOfVecs[1][0]<<endl;//prints 100
    
        return 0;
    }
    

    WITH ARRAY OF POINTERS

    int main()
    {
        int* arrayOfPtrs[9];
    
        for(int index = 0;index<9;index++)
        {
            int sizeOfArray = //determine the size of each array
            arrayOfPtrs[index] = new int[sizeOfArray];
    
            //initialize all to zero if you want or you can skip this loop
            for(int k=0;k<sizeOfArray;k++)
                arrayOfPtrs[index][k] = 0;
    
        }
    
        for(int index = 0;index<9;index++)
        {
            for(int k=0;k<6;k++)
                cout<<arrayOfPtrs[index][k]<<endl;
        }
    
        return 0;
    

    }

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

Sidebar

Related Questions

I have an array that I would like to sort using a date field
I have an array of dictionaries that I would like to go through to
I would like to have a function that returns something like an array of
I have an array that looks something like this: array( (int) 0 => array(
say I have a 1D array like int[] x = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16} . I would
Hi all, I have an array of long that I would like to write
I would like to have an array (or a vector) and at each position
I have the array shown below. I would like to have a resultant array
I would like to have a static char array member initialized in terms of
I have an array which i would like to sort it based on values

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.