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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:30:20+00:00 2026-06-10T09:30:20+00:00

I have a statically declared array like this Cell SMatrix_A[36][10] . When I use

  • 0

I have a statically declared array like this Cell SMatrix_A[36][10]. When I use SMatrix_A directly in my code (Cell foo = SMatrix_A[12][8]), everything works fine. However, what I really want is to declare several of these matrices (SMatrix_A, SMatrix_B, etc) and then have a pointer variable switch between them at runtime.

I’m imagining code like this (asusming SMatric_A, B, C are already declared and this is all in the same file scope):

Cell *curMatrix = SMatrix_B;
Cell foo,bar;
...
foo = curMatrix[13][2];

The compiler gives me an: Incompatable pointer types assigning 'Cell*' from 'Cell[36][10]' on the initial assignment to curMatrix. I thought that referring to an array variable without subscripts was going to give me a pointer type with the value being the first location of the array.

Am I just missing a cast or something?

  • 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-10T09:30:21+00:00Added an answer on June 10, 2026 at 9:30 am

    My previous answer is totally wrong, so I’m giving it another shot!

    #import <Foundation/Foundation.h>
    
    typedef int matrix_t[3][3];
    
    matrix_t matrix = { { 1, 2, 3}, { 4, 5, 6}, { 7, 8, 9} };
    
    int main(int argc, char *argv[])
    {
        matrix_t *matrixPtr = &matrix;
    
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                NSLog(@"%i", (*matrixPtr)[i][j]);
            }
        }
        return 0;
    }
    

    You need to typedef your 2D array type (this is likely a good idea so that your SMatrix_A, SMatrix_B all have the same size). Then you can create pointers to it as normal. Note that you must dereference the pointer before you index it.

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

Sidebar

Related Questions

For a rather obscure use case I'd like to have a (large) statically linked
I have a programming experience with statically typed languages. Now writing code in Python
This is a biggie. I have a well-structured yet monolithic code base that has
Often I could use some tools to statically analyze my code in order to
Seems like we could just have a normal statically checked assignment. I'm not sure
If you have a statically allocated array, the Visual Studio debugger can easily display
I have a table layout in which i have declared a button statically in
Say you have 2 share libraries, lib1.so and lib2.so, that both have libcommon.a statically
Many statically typed languages have parametric polymorphism. For example in C# one can define:
I have shared object A.so which statically links to libssl.a & another shared object

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.