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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:19:54+00:00 2026-05-11T03:19:54+00:00

On the discussion of dynamic memory here: Intro to C Pointers and Dynamic Memory

  • 0

On the discussion of dynamic memory here: ‘Intro to C Pointers and Dynamic Memory’

The author states:

A memory block like this can effectively be used as a more flexible array. This approach is actually much more common in real-world C programs. It’s also more predictable and flexible than a ‘variable size array’

The type of memory block he is talking about is as such:

const int size = 5; int * array = calloc(size, sizeof(int)); 

and then using another pointer to iterate over the array:

int * index = array; for (i = 0; i < size; i++) {     *index = 1; // or whatever value     index++; } 

My question is how is this method better than a standard variable sized array like this?:

int array[variable]; 

or dynamic:

char name[] = 'Nick'; 

The author doesn’t really shed much light as to why I should prefer the former method to the latter. Or more specifically: How is it more ‘predictable and flexible’?

  • 1 1 Answer
  • 3 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-11T03:19:55+00:00Added an answer on May 11, 2026 at 3:19 am

    If you declare int array[variable] the memory will be allocated on the stack which is not very good for large, relatively permanent data structures (such as one you might want to return). You don’t need to free memory manually if you use the array syntax since it’s freed when it goes out of scope. calloc on the other hand will allocate memory dynamically at run time on the heap. You’ll have to free it yourself as soon as you’re finished with it.

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

Sidebar

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.