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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:30:23+00:00 2026-06-02T16:30:23+00:00

Possible Duplicate: Differences between dynamic memory and “ordinary” memory I was reading the C++

  • 0

Possible Duplicate:
Differences between dynamic memory and “ordinary” memory

I was reading the C++ tutorial and I don’t understand why I need to declare dynamic memory, this is what the tutorial says:

Until now, in all our programs, we have only had as much memory available as we declared for our variables, having the size of all of them to be determined in the source code, before the execution of the program.

And then it says that we have to use new and delete operators to use dynamic memory.
However, I seem to be using dynamic memory when declare a pointer, e.g. char* p, for which I have not specified the length of the array of characters. In fact, I thought that when you use a pointer you are always using dynamic memory. Isn’t it true?
I just don’t see the difference between declaring a variable using new operator and not. I don’t really understand what dynamic memory is. Can anyone explain me this?

  • 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-02T16:30:24+00:00Added an answer on June 2, 2026 at 4:30 pm

    I thought that when you use a pointer you are always using dynamic
    memory. Isn’t it true?

    No it’s not true, for example

    int i;
    int *p = &i; // uses a pointer to static memory, no dynamic memory.
    

    However, I seem to be using dynamic memory when declare a pointer,
    e.g. char* p, for which I have not specified the length of the array
    of characters

    char[100] string;
    char* p = &(string[0]);  // Same as above, no dynamic memory.
    

    You need dynamic memory when you can’t tell how big the data structure needs to be.

    Say you’ve to read some ints from a file and store them in memory. You have no idea how many ints you need. You could pick a figure of 100, but then your program breaks if there are 101. You could pick 100,000 hoping that’s enough, but it’s waste of resources if there’s only 10 in the file, and again, it breaks if there’s 100,001 ints in the file.

    In this scenario your program could iterate through the file, count the number of ints, then dynamically create an array of the correct size. Then you pass over the file a second time reading the ints into your new array.

    Static v’s Dynamic Memory
    Static memory is static because once the program is compiled it can’t be changed, it is static. Variables you declare in functions, and members declared on classes / structs are static. The compiler calculates exactly how many of each its going to need as each method gets called.
    Dynamic memory is a “pool” of memory that can be made available to your program on demand, at run time.
    The compiler only knows it needs to allocate some (probably unknown) amount of that memory, and to release that memory back to the dynamic memory pool.

    Hope this helps.

    P.S. Yes, there are more efficient ways to get an unknown number of items into memory, but this is the simplest to explain

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

Sidebar

Related Questions

Possible Duplicate: Real differences between “java -server” and “java -client”? I've seen the argument
Possible Duplicate: Difference between e.target and e.currentTarget I don't really understand the difference between
Possible Duplicate: What are the specific differences between .msi and setup.exe file? I am
Possible Duplicate: What are the differences between pointer variable and reference variable in C++?
Possible Duplicate: In WPF, what are the differences between the x:Name and Name attributes?
Possible Duplicate: Difference between pointer variable and reference variable in C++ I am reading
Possible Duplicate: Differences between Private Fields and Private Properties Let's say I have a
Possible Duplicate: What are the differences between pointer variable and reference variable in C++?
Possible Duplicate: What are major differences between C# and Java? I believe it was
Possible Duplicate: What are the differences between using int[][] and int[,]? I just came

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.