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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:29:28+00:00 2026-05-11T00:29:28+00:00

I am trying to return an array Data Member from one smaller 2D Array

  • 0

I am trying to return an array Data Member from one smaller 2D Array Object, and trying to insert the array into a larger 2D array object. But when attempting this, I came into two problems.

First problem is that I want to return the name of the 2D array, but I do not know how to properly syntax to return 2D Array name.

This is what my 2D Array data member looks like

 private: int pieceArray[4][4]; // 2D Smaller Array 

and I want to return this array into a function, but this one causes a compiler error:

 int Piece::returnPiece() {     return pieceArray; //not vaild     // return the 2D array name } 

I tired using this return type and it worked:

 int Piece::returnPiece() {     return pieceArray[4][4]; } 

But I am unsure if this is what I want, as I want to return the array and all of it’s content.

The other problem is the InsertArray() function, where I would put the returnPiece() function in the InsertArray()’s argument.

The problem with the InsertArray() is the argument, heres the code for it:

 void Grid::InsertArray( int arr[4][4] ) //Compiler accepts, but does not work {     for(int i = 0; i < x_ROWS ; ++i)     {          for (int j = 0; j < y_COLUMNS ; ++j)          {              squares[i][j] = arr[i][j];          }     } } 

The problem with this is that it does not accept my returnPiece(), and if i remove the ‘[4][4]’, my compiler does not accept.

Mostly all these are syntax errors, but how do I solve these problems?

  1. Returning the whole pieceArray in returnPiece()
  2. The correct syntax for the argument in InsertArray()
  3. The argument of InsertArray() accepting the returnPiece()

These 3 are the major problems that I need help with, and had the same problem when I attempt to use the pointer pointer method. Does anyone know how to solve these 3 problems?

  • 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. 2026-05-11T00:29:29+00:00Added an answer on May 11, 2026 at 12:29 am

    When passing your array around, you have to decide whether or not you want to make a copy of the array, or if you just want to return a pointer to the array. For returning arrays, you can’t (easily) return a copy – you can only return a pointer (or reference in C++). For example:

    // Piece::returnPiece is a function taking no arguments and returning a pointer to a // 4x4 array of integers int (*Piece::returnPiece(void))[4][4] {     // return pointer to the array     return &pieceArray; } 

    To use it, call it like so:

    int (*arrayPtr)[4][4] = myPiece->returnPiece(); int cell = (*arrayPtr)[i][j];  // cell now stores the contents of the (i,j)th element 

    Note the similarity between the type declaration and using it – the parentheses, dereferencing operator *, and brackets are in the same places.

    Your declaration for Grid::InsertArray is correct – it takes one argument, which is a 4×4 array of integers. This is call-by-value: whenever you call it, you make a copy of your 4×4 array, so any modification you make are not reflected in the array passed in. If you instead wanted to use call-by-reference, you could pass a pointer to an array instead:

    // InsertArray takes one argument which is a pointer to a 4x4 array of integers void Grid::InsertArray(int (*arr)[4][4]) {      for(int i = 0; i < x_ROWS; i++)      {          for(int j = 0; j < y_COLUMNS ; j++)              squares[i][j] = (*arr)[i][j];      } } 

    These type declarations with pointers to multidimensional arrays can get really confusing fast. I recommend making a typedef for it like so:

    // Declare IntArray4x4Ptr to be a pointer to a 4x4 array of ints typedef int (*IntArray4x4Ptr)[4][4]; 

    Then you can declare your functions much more readable:

    IntArray4x4Ptr Piece::returnPiece(void) { ... } void Grid::InsertArray(IntArray4x4Ptr arr) { ... } 

    You can also use the cdecl program to help decipher complicated C/C++ types.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The answer turned out to be because I was creating… May 12, 2026 at 9:25 pm
  • Editorial Team
    Editorial Team added an answer Another hint is to have a look at your IIS… May 12, 2026 at 9:25 pm
  • Editorial Team
    Editorial Team added an answer What about having two classnames? <div class='foo fooDragable'></div> <div class='foo… May 12, 2026 at 9:25 pm

Related Questions

Here's what I'm trying to do ... Im using Flash to call an AMFPHP
I am looking for the fastest way to de/interleave a buffer. To be more
I'm trying to select a column from a single table (no joins) and I
Here's the node definition: struct node{ int data; stuct node * left; struct node

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.