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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:11:49+00:00 2026-06-12T00:11:49+00:00

In which of these steps memory is allocated while trying to allocate 2D array

  • 0

In which of these steps memory is allocated while trying to allocate 2D array of 20×10

step 1: int (*p)[10];

step 2: p = malloc( 20 * sizeof(*p) );

Do all the memory(20 x 10 x 4 bytes) are allocated in step 2
or some amount of memory is allocated in step 1 also?

  • 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-12T00:11:50+00:00Added an answer on June 12, 2026 at 12:11 am

    Step 1 creates a pointer as an automatic variable. The type pointed to is array-of-10-int.

    Step 2 allocates memory for 20 such arrays (print out sizeof(*p) to see how big each array is — the allocated block is 20 times that), and assigns a pointer to that block of memory to p.

    So, p now points to the first element of an array of 20 arrays-of-10-int.

    If it helps understand, the code is equivalent to:

    typedef int my_array[10];
    my_array *p = malloc(20 * sizeof(my_array));
    

    The second line of that probably looks more like what you’re used to with malloc. You still can (and should) use sizeof(*p) rather than sizeof(my_array), though.

    malloc is very simple — it takes a number, and it allocates that many bytes. It doesn’t care what type the memory is for. So when in doubt how much memory you’re allocating, you can always simply print that number (or look at it in your debugger).

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

Sidebar

Related Questions

I am very confused over the time at which memory is allocated to Java
Are there any online resources which show the basic steps to access the Microsoft
I have a view that contains two NSTextFieldCell s. The size at which these
Which of these two platforms/ecosystems are better for writing web applications/websites? I am not
Which amongst these would be well suited for a scalable server side TCP socket
Which of these queries is more efficient, and would a modern DBMS (like SQL
Which of these two statements is faster/better practice? myList.Where(x => { bool itemOne= x.ItemOne
I was wondering which of these two scenario's works best for swapping between 2
I'm not sure which is these is appropriate for my current application. I need
My real Question is which of these is more efficient in terms of loading

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.