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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:57:00+00:00 2026-05-30T21:57:00+00:00

Consider the following C++ code example: int array_1[] = {5,6,7}; int array_2[] = {6,7,8,9};

  • 0

Consider the following C++ code example:

int array_1[] = {5,6,7};
int array_2[] = {6,7,8,9};
int array_3[] = {2,3};

int* meta_array[] = {array_1, array_2, array3};

Now I want to iterate over all of the elements in the sub arrays of meta_array without causing a seg fault.

The problem, of course, is that I have no way to get the size of the arrays to avoid overstepping their bounds.

I can do sizeof array_1 / sizeof array_1[0] to get the size of a common 1-dimensional array pretty quickly, but once I’m in the meta_array, every element has been converted to a pointer, and so sizeof will return the byte size of the pointer instead of the entire array. Thus, sizeof meta_array[0] / sizeof meta_array[0][0] doesn’t really do much to help my cause.

Is there a standard solution to iterating over nonuniform multidimensional arrays out there already, or should I just go ahead and use std::vector?

  • 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-30T21:57:02+00:00Added an answer on May 30, 2026 at 9:57 pm

    use std::vector.

    or, use a “closing” number but you must be sure there will be no elements with that value, ever.

    int array_1[] = {5,6,7,-1};
    int array_2[] = {6,7,8,9,-1};
    int array_3[] = {2,3,-1};
    
    int*  meta_array[] = 
    {
      array_1, 
      array_2, 
      array_3,
      NULL
    };
    
    for(int i=0; meta_array[i] != NULL; ++i)
    {
       for(int j=0; meta_array[i][j] != -1; ++j)
           printf("%d",  meta_array[i][j]);
       printf("\n");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?
Consider the following code: abstract class SomeClassX<T> { // blah } class SomeClassY: SomeClassX<int>
Consider the following code: template <int dim> struct vec { vec normalize(); }; template
Consider the following code: writer.c mkfifo(/tmp/myfifo, 0660); int fd = open(/tmp/myfifo, O_WRONLY); char *foo,
Consider the following code template<typename T, int N> struct A { typedef T value_type;
Consider the following code: void f(byte x) {print(byte);} void f(short x) {print(short);} void f(int
Consider the following code: int SomeField; void Foo([Pure] Func<int, object> getData) { Contract.Requires(getData !=
please consider following code #include <iostream> using namespace std; class Digit { private: int
Consider the following code: var myDict = new Dictionary<string, int>(); myDict.Add(Key1, 1); myDict.Add(Key2, 2);
Consider the following example: interface IBase1 { int Percentage { get; set; } }

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.