IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
COne Dimensional Arrays : Dynamic Allocation
<07.09>
/* A dynamically-allocated 1-D array */ #include <stdio.h> #include <stdlib.h> int main (void) { double* array; //declare a pointer only int i, size; //ask user for size of array printf ("How large do you want your array? "); scanf ("%d", &size); //allocate the array in the heap with calloc array = (double *) calloc (size, sizeof(double)); //printing the array for verification. calloc initializes all cells to 0. for (i = 0; i < size; ++i) printf ("%6.2lf", array[i]); //freeing the memory allocation free (array); return (0); }
Hergestellt in Deutschland / Made in Germany
How large do you want your array? 7 0.00 0.00 0.00 0.00 0.00 0.00 0.00
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland