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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:07:50+00:00 2026-06-04T00:07:50+00:00

Watching some code found on internet I came across this piece of code: int

  • 0

Watching some code found on internet I came across this piece of code:

int (*p)[3];

p = (int(*)[3]) calloc(5*3,sizeof(int));

is it just a way to alloc a matrix?

I understand that int (*p)[3] creates a pointer to an array of 3 int, but I’m not sure about the calloc call: I know that calloc allocate and initialize a number of int (in this case) equal to the first parameter (5*3).
Thus, if I assign it to p it should mean that the pointer now points to the just allocated memory location.

So, since I know my reasoning is wrong, may somebody correct me?

  • 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-04T00:07:51+00:00Added an answer on June 4, 2026 at 12:07 am
    int (*p)[3];
    

    You’re true that this is a pointer to an array of three ints, but this pointer could also point to the beginning of an array of arrays of three ints.

    p = (int(*)[3]) calloc(5*3,sizeof(int));
    

    Here, you allocate 5 * 3 ints to this pointer. As int[3] has 3 ints, you just allocated 5 such int[3] arrays.

    You may then refer to these int[3] arrays as

    p[0] … p[4]

    so you get a two-dimensional array ranging

    p[0][0] … p[0][2]

    p[4][0] … p[4][2]

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

Sidebar

Related Questions

I am watching a video about [LINQ][1] and came across a problem. In this
I've been watching some videos on asp.net MVC, I think this question is just
Considering this code: std::vector<myObject*> veryLargeArray; for (int i = 0; i < veryLargeArray.size(); ++i)
While I was watching some code about singleton's in python I decided to write
I just finished watching the Google clean code video on YouTube (see link ,
Ok this must be something dumb. I ran into this when moving some code
I was just watching a video on MSDN Channel 9 which can be found
Many times when I am watching others code I just want to find where
Watching some videos they talk about endpoints and im not sure what the differences
I've been watching some Railscast episodes and it looks like he's using Sublime Text

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.