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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:54:50+00:00 2026-06-01T06:54:50+00:00

I have code to dynamically allocate an array of 100 doubles to a pointer

  • 0

I have code to dynamically allocate an array of 100 doubles to a pointer and initialize the memory with values from 1.0 to 100.0.

My question is, in the code below why don’t I have to write *ptr++ at each iteration of the for loop. I’ve tried it and it doesn’t work.

void allocate_array(){
    double *ptr;
    ptr= (double*)malloc(sizeof(double)*100);
    int i=0;
    float j=0.0;
    for(i=0;i<100;i++){
        *ptr=j++;
        printf(" %0.1lf\n",*ptr);
    }
}
  • 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-01T06:54:52+00:00Added an answer on June 1, 2026 at 6:54 am

    Well, you don’t have to do anything. In your code, you don’t initialize the whole array – you just assign 100 different values to its first member. Your code is just like:

    double d;
    for(i=0;i<100;i++){
                d=j++;
                printf(" %0.1lf\n",d);
    }
    

    If you want to initialize the whole array, do something like:

    double *temp=ptr;
    for(i=0;i<100;i++){
                *temp=j++;
                printf(" %0.1lf\n",*temp++);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have c++ code that attempts to dynamically allocate a 2d array of bytes
This is the code that I have to dynamically declaring an array inside a
I have a 2 dimensional array dynamically allocated in my C code, in my
This question is in C++. I am trying to dynamically allocate an array of
I have a question regarding some memory management in C. I have to allocate
I'm using the code above to dynamically allocate an array, do some work inside
I have code that dynamically load 10 different textfields in viewdidload method now if
I have some code that dynamically creates a new button through JavaScript that when
I have recently come across a situation where code is dynamically loading some libraries,
I have this code $(.delete2).click(function() { $('#load2').fadeIn(); } I have dynamically added item via

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.