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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:20:42+00:00 2026-05-26T01:20:42+00:00

I have 2 2D arrays that represent a maze const char maze1[10][11] and const

  • 0

I have 2 2D arrays that represent a maze

const char maze1[10][11]
and
const char maze2[20][21]

I’m trying to create 1 function to handle both mazes like so:

void solveMaze(maze[][])
{
}

and just pass the maze like solveMaze(maze1);
However, I have to supply a size for the array, which is different depending on which maze is being passed in. Without overloading the function or using function templates, how can I have 1 function to handle both arrays?

  • 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-26T01:20:42+00:00Added an answer on May 26, 2026 at 1:20 am

    C++ answer

    Use std::vector:

    // Initialize the vector with 11 rows of 10 characters
    std::vector<std::vector<char> > maze(11, std::vector<char>(10));
    
    void solveMaze(const std::vector<std::vector<char> > &maze) {
        // note that you can access an element as maze[x][y]
    }
    

    The boost::multi_array is slightly more efficient (if you’re allowed to use boost). I think it goes something like this:

    boost::multi_array<char, 2> maze(boost::extents[10][11]);
    
    void solveMaze(const boost::multi_array<char, 2> &maze) {
        // note that you can access an element as maze[x][y]
    }
    

    C answer

    Use pointers:

    const char maze1[10][11];
    
    void solveMaze(char *maze, size_t x_length, size_t y_length) {
        // note that you can access an element as maze[x + (x_length * y)]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 2D arrays that represent a maze const char maze1[10][11] and const
I have two arrays that I create like this: public int GameBoard[][] = new
I'm trying to come up with a way combine two arrays that have different
I have two arrays of data that I'm trying to amalgamate. One contains actual
In my app I have 5 String arrays that represent different fields of objects.
Sure, you can have nested lists to represent multidimensional arrays, but that seems costly...
I have an array of latitude/longitude coordinate pairs that represent a polygon. I'm trying
I have two arrays that I would like to compare and ultimately wind up
I have 2 arrays that I would like to render in a template, one
I have two numpy arrays that define the x and y axes of a

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.