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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:23:01+00:00 2026-05-31T09:23:01+00:00

I have the following struct: typedef struct { int someArray[3][2]; int someVar; } myStruct;

  • 0

I have the following struct:

typedef struct {
    int someArray[3][2];
    int someVar;
} myStruct;

If I create an array of this struct in my main (like the following), how would I initialize it?

int main() {
    myStruct foo[5];
}

I want to initialize the above array of struct in a way similar to initilazing a normal array (see below):

int main() {
    int someArray[5] = {1,4,0,8,2};
}
  • 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-31T09:23:03+00:00Added an answer on May 31, 2026 at 9:23 am

    Work from the outside in. You know you have an array of 5 things to initialize:

    mystruct foo[5] = { 
                        X, 
                        X, 
                        X, 
                        X, 
                        X 
                      };
    

    where X is a stand-in for initializers of type mystruct. So now we need to figure out what each X looks like. Each instance of mystruct has two elements, somearray and somevar, so you know your initializer for X will be structured like

    X = { Y, Z }
    

    Substituting back into the original declaration, we now get

    mystruct foo[5] = { 
                        { Y, Z }, 
                        { Y, Z }, 
                        { Y, Z }, 
                        { Y, Z }, 
                        { Y, Z } 
                      };
    

    Now we need to figure out what each Y looks like. Y corresponds to an initializer for a 3×2 array of int. Again, we can work from the outside in. You have an initializer for a 3-element array:

    Y = { A, A, A }
    

    where each array element is a 2-element array of int:

    A = { I, I }
    

    Subsituting back into Y, we get

    Y = { { I, I }, { I, I }, { I, I } }
    

    Substituting that back into X, we get

    X = { { { I, I }, { I, I }, { I, I } }, Z }
    

    which now gives us

    mystruct foo[5] = {
                        { { { I, I }, { I, I }, { I, I } }, Z },
                        { { { I, I }, { I, I }, { I, I } }, Z },
                        { { { I, I }, { I, I }, { I, I } }, Z },
                        { { { I, I }, { I, I }, { I, I } }, Z },
                        { { { I, I }, { I, I }, { I, I } }, Z }
                      };
    

    Since Z is a stand-in for an integer, we don’t need to break it down any further. Just replace the Is and Zs with actual integer values, and you’re done:

    mystruct foo[5] = {
                        {{{101, 102}, {201, 202}, {301, 302}}, 41},
                        {{{111, 112}, {211, 212}, {311, 312}}, 42},
                        {{{121, 122}, {221, 222}, {321, 322}}, 43},
                        {{{131, 132}, {231, 232}, {331, 332}}, 44},
                        {{{141, 142}, {241, 242}, {341, 342}}, 45}
                      };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following: typedef struct { int itemSize; int count; void *list;
There is big array of entries having the following type: typedef struct { int
I have the following struct: typedef struct{ int vin; char* make; char* model; int
I have a question. I have the following struct : typedef struct{ int vin;
If I have the following: typedef struct _MY_STRUCT { int a; float b; }
I have declared the following struct: typedef struct _RECOGNITIONRESULT { int begin_time_ms, end_time_ms; char*
I have following code #include <stdio.h> #include<ctype.h> typedef struct { int Type; int Type2;
Suppose I have the following code: typedef struct { char **p; } STRUCT; int
I have the following C-code: #include<stdio.h> #include<stdlib.h> typedef struct node { int a; }node;
I have the following struct in C++: #define MAXCHARS 15 typedef struct { char

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.