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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:34:14+00:00 2026-05-26T10:34:14+00:00

I would like to build a function that takes a multidimensional array and prints

  • 0

I would like to build a function that takes a multidimensional array and prints it like a grid. I’m having trouble with it because c++ doesn’t allow a function to have a multidimensional array argument unless you specify its length. There is a question about it on here, that was answered using vectors. I haven’t learned how to use vectors yet, so please don’t use them in an answer, or at least provide a good tutorial on them if you do.

Anyway, I was wondering if it’s possible to return an array in c++… I started programming with javascript, so the first solution I thought of was to do something like

int gen(int len){
    return int arr(int a[][len]){
        cout << a[0][0];
    };
}

I knew it wouldn’t work, tried it, and wasn’t surprised when it didn’t. Is there a way to do something like this though?

  • 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-26T10:34:15+00:00Added an answer on May 26, 2026 at 10:34 am

    In C++ you can pass array by reference. With making an array a template, it’s possible to receive any length in the function. For example,

    template<size_t SIZE1>
    void print (int (&arr)[SIZE1])
    { ... }
    
    template<size_t SIZE1, size_t SIZE2>
    void print (int (&arr)[SIZE1][SIZE2])
    { ... }
    
    template<size_t SIZE1, size_t SIZE2, size_t SIZE3>
    void print (int (&arr)[SIZE1][SIZE2][SIZE3])
    { ... }
    

    This pattern will internally create a unique function for every different size of array. It offers ease of use, but may increase the code size.

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

Sidebar

Related Questions

I would like to build a regexp in Java that would be passed in
I would like to build an application that will run on a web, this
I would like to build a query that will pull the number of rows
I would like to build a cross-platform GUI application in Python that displays PostScript
What I'm looking for is a how to build a function that takes a
I would like to build an excel VBA program to find all the match
I would like to build some code which calls some code on loadup of
I would like to build a static version of QT Library for X11 like
I would like to build some smaller scale but hightly customized documentation sites for
I would like to build a simple animation for a school project. I want

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.