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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:23:31+00:00 2026-06-08T02:23:31+00:00

Is there a way to pass ‘std::vector 2d’ as a pointer to ‘2d c

  • 0

Is there a way to pass ‘std::vector 2d’ as a pointer to ‘2d c array’ to a function.

I know you can pass std::vector 1d as a pointer to c array to some function.
for example,
function:

void foo(char* str); //requires the size of str to be 100 chars

std::vector<char> str_;
str_.resize(100);
foo(&str_[0]); //works

I’m wondering if it is possible for 2d vectors too like for
function

void foo(char** arr_2d);

and vector

std::vector<std::vector<char>> vector_2d;

I tried the following code but im getting some error related to heap corruption.

std::vector<std::vector<unsigned char>> vector_2d;
//assuming function expects the size of the vector to be 10x10  
vector_2d.resize(10);
for(int i=0;i<10;i++)
{
    vector_2d[i].resize(10);
}
foo(&vector_2d[0]);//error here
  • 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-08T02:23:33+00:00Added an answer on June 8, 2026 at 2:23 am

    Here’s what you can do:

    std::vector< std::vector<unsigned char> > vector_2d;
    vector_2d.resize(10);
    std::vector<unsigned char*> ptrs(vector_2d.size());
    for(int i=0;i<10;i++)
    {
        vector_2d[i].resize(10);
        ptrs[i] = &vector_2d[i][0];
    }
    foo(&ptrs[0]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there a way to pass external parameter into Grid renderer function? For example,
Is there a way to pass some extra parameter to the function that is
Is there a way i can pass information into a nested function ? The
is there a way to pass an array to a member function? i tried
Is there a way to pass a variable to the choice() function for a
Is there a way to pass an array of String to a resource bundle
Is there a way to pass an unlimited amount of arguments to a function,
Is there a way to pass a list as a function argument to eval()
Is there some way to pass a table-valued parameter to a stored procedure in
Is there a way to pass through a variable to Kohana messages, which can

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.