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

  • Home
  • SEARCH
  • 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 71663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:55:23+00:00 2026-05-10T19:55:23+00:00

I am modifying some code and came across a declaration that I am having

  • 0

I am modifying some code and came across a declaration that I am having trouble understanding:

int *userMask[3][4] = {0}; 

What exactly is this pointing to? Is it a matrix where every element is a pointer? Or is it pointing to a matrix of size [3][4]?

Thanks


I guess my question is how userMask[2][maskElement][user] can work when it is declared as int. Wouldn’t userMask have to be int[] for that to work properly? I must not be understanding this right…

On a side note, thanks for your suggestion about cdecl Robert. However, does anyone know how to use it in an XP command prompt? All I can get is syntax error 🙁

  • 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. 2026-05-10T19:55:24+00:00Added an answer on May 10, 2026 at 7:55 pm

    Short answer

    Given userMask is declared as

    int *userMask[3][4]; 

    then userMask has type int*[3][4]. It’s a 2d array of pointers to int. The size of the outer dimension is 3, the size of the inner dimension is 4. Really that is nothing more than a 3-element 1d array which element type is another 4-element 1d array which element type is int*.

    Steps explained

    So if you do

    userMask[2][maskElement][user] 

    then essentially with the first two indices you pick the particular pointer out of the 2d array:

    int * p = userMask[2][maskElement]; 

    then you pick an int somewhere offset from that pointer by doing

    p[user] 

    now that code is all in userMask[2][maskElement][user].

    Valid C Code

    To do it step by step with valid c code (don’t worry if you don’t understand everything yet in the following):

    int * userMask[3][4] = { { 0 } }; int ** pa = userMask[2]; /* int*[4] becomes int** implicitly */ int * pi = pa[maskElement]; int i = pi[user];  assert(i == userMask[2][maskElement][user]); 

    Difference between Arrays and Pointers

    So i think i show you something important. The array above does not contain pointers to arrays. Lets look how different they behave, which many c programmers don’t expect:

    int array[5][4][3]; /* int[4][3] implicitly converts to int(*)[3] (pointer to first element) */ int (*parray)[3] = array[0];  int ** pint = (int**) array[0]; /* wrong!! */ 

    Now, what will happen if we do parray[1] and pint[1] ? The first will advance parray by sizeof(int[3]) bytes (3 * sizeof(int)), the second will advance by only sizeof( int* ) bytes. So actually while the first gives you the correct array array[0][1], the second will give you ( char * )array[0] + sizeof( int* ), which is somewhere we don’t really want it to be. But grabbing the wrong offset is not all about it. Because it doesn’t know an array is accessed, it will try to interpret what is at pint[1] as an int*. Say your array was initialized with 0x00. Then it will do the next index step based off address 0x00 (Doing pint[1][0] for example). Oh noes – utterly undefined behavior! So it’s really important to stress the difference.

    Conclusion

    This was more than you asked for, but I think it’s quite important to know these details. Especially if you want to pass 2d arrays to functions then this knowledge is really useful.

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

Sidebar

Ask A Question

Stats

  • Questions 114k
  • Answers 114k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer java.lang.System.getProperty("os.arch") should help -- giving "arm", "amd64", and the like. May 11, 2026 at 10:16 pm
  • Editorial Team
    Editorial Team added an answer This is difficult to answer accurately since parallel processing is… May 11, 2026 at 10:16 pm
  • Editorial Team
    Editorial Team added an answer "Counts answer" Please update these counts and feel free to… May 11, 2026 at 10:16 pm

Related Questions

I need to find a way to stop a while statement when a messagebox
I am modifying a Nant build script to run some unit tests. I have
I'm an experienced C programmer dipping my toes in OO design (specifically C++). I
I am building an application plugin in Python which allows users to arbitrarily extend

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.