Dynamic Arrays
You can also allocate memory in RAM for arrays, which are called dynamic!
To create a dynamic array, just specify the type and number of elements you want in square brackets by declaring:
x = new int[5]; // Request memory
delete []x; // Delete array pointed to x
Dynamic memory is extremely useful in many situations when your program doesn’t know how much place it needs. For instance, when your code needs to read a file or you want to create an array depending on user input.
Obrigado pelo seu feedback!
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Pergunte-me perguntas sobre este assunto
Resumir este capítulo
Mostrar exemplos do mundo real
Awesome!
Completion rate improved to 2.94
Dynamic Arrays
Deslize para mostrar o menu
You can also allocate memory in RAM for arrays, which are called dynamic!
To create a dynamic array, just specify the type and number of elements you want in square brackets by declaring:
x = new int[5]; // Request memory
delete []x; // Delete array pointed to x
Dynamic memory is extremely useful in many situations when your program doesn’t know how much place it needs. For instance, when your code needs to read a file or you want to create an array depending on user input.
Obrigado pelo seu feedback!