Groups | Search | Server Info | Login | Register


Groups > alt.comp.lang.c++.misc > #29

Dynamic Arrays

From Student Project <student@invalid.invalid>
Newsgroups comp.lang.c++, alt.comp.lang.c++.misc
Subject Dynamic Arrays
Date 2024-10-29 04:30 +0000
Organization To protect and to server
Message-ID <vfpnit$ob9e$1@paganini.bofh.team> (permalink)

Cross-posted to 2 groups.

Show all headers | View raw


Do you guys use dynamic arrays to create arrays at compile time (without 
using vector class)?  For example:

/********************************************************************************/
#include <iostream>

void Generate_Random(size_t size);

int main(void)
{
     // generate dynamic array by changing 20 to something else!
     Generate_Random(20);
}

void Generate_Random(size_t size)
{
     srand((unsigned)time(NULL));
     int *numbers = new int[size]{0};

     /* initialize the first number to 0 then don't use it
      * start the for loop from 1 as usual to make it easy
     */
     numbers[0] = 0;

     for (size_t i = 1; i <= size; i++)
     {
         numbers[i] = 100 + rand() % 101;
     }

     for (size_t i = 1; i <= size; i++)
     {
         std::cout << numbers[i] << ", ";
     }
}

/********************************************************************************/



Back to alt.comp.lang.c++.misc | Previous | NextNext in thread | Find similar


Thread

Dynamic Arrays Student Project <student@invalid.invalid> - 2024-10-29 04:30 +0000
  Re: Dynamic Arrays Barry Schwarz <schwarzb@delq.com> - 2024-10-28 21:48 -0700
  Re: Dynamic Arrays David Brown <david.brown@hesbynett.no> - 2024-10-29 08:56 +0100
  Re: Dynamic Arrays Paavo Helde <eesnimi@osa.pri.ee> - 2024-10-29 13:47 +0200

csiph-web