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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:42:13+00:00 2026-06-13T05:42:13+00:00

Suppose I declare an array as int myarray[5] Or declare it as int*myarray=malloc(5*sizeof(int)) Will

  • 0

Suppose I declare an array as int myarray[5]

Or declare it as int*myarray=malloc(5*sizeof(int))


Will both the declarations set equal amount of memory in number of bytes?
Without considering that the former declaration is for the stack and the latter on the heap.

Thank you!

  • 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-13T05:42:15+00:00Added an answer on June 13, 2026 at 5:42 am

    There’s a fundamental difference, that may not be apparent in the way you use myarray:

    • int myarray[5]; declares an array of five integers, and the array is an automatic variable (and it is uninitialized).

    • int * myarray = malloc(5 * sizeof(int)); declares a variable that is a pointer to an int (also as an automatic variable), and that pointer is initialized with the result of a library call. That library call promises to make the resulting pointer point to a region of memory that’s big enough to store five consecutive integers.

    Because of pointer arithmetic, array-to-pointer decay and the convention that a[i] is the same as *(a + i), you can use both variables in the same way, namely as myarray[i]. This is of course by design.

    If you’re looking for a difference, then maybe the following helps: The array-of-five-ints is a single object, and it has a definite size. By contrast, the malloc library call doesn’t create any objects. It just sets aside enough memory (and suitably aligned), but it could for example allocate a lot more memory.

    (In C++ there’s of course the additional distinction between memory and objects.)

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

Sidebar

Related Questions

suppose I declare a dynamic array like int *dynArray = new int [1]; which
Suppose I declared an array as following: int myArr = [someSize]; Now I put
Suppose I have something like this int strLen; printf(Please enter a number: ); scanf(%d,
Suppose I've got a set of arrays and strings and constants: const int a[]={0x01,
Possible Duplicate: How to declare an array in Java? Suppose I have an object
I stumbled across this problem in F#. Suppose, I want to declare two types
Is it possible to declare an array of pointers and later on initialize either
Do you think what this discussion about memory-map of 2D array is correct? Especially
suppose I have a class like class ABC { int ID; public string Name;
Suppose that the function void foo(int n, double x[]) sorts the n-vector x ,

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.