Skip to content

Instantly share code, notes, and snippets.

@RolandWarburton
Created September 28, 2019 02:29
Show Gist options
  • Save RolandWarburton/fe8f7cd39237be587f182db38f8adfe3 to your computer and use it in GitHub Desktop.
Save RolandWarburton/fe8f7cd39237be587f182db38f8adfe3 to your computer and use it in GitHub Desktop.
realloc arrays 2. electric boogaloo
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int *cc = new int[20];
int size = 0;
for (size_t i = 0; i < 5; i++)
{
cout << "enter number: ";
cin >> cc[i];
size++;
}
cc = (int *)realloc(cc, sizeof(int) * size);
for (size_t i = 0; i < size; i++)
{
cout << cc[i];
}
cout << "\n";
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment